mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-21 20:24:42 +00:00
cdp: call Page.getFrameTree on startup when possible
This commit is contained in:
@@ -191,30 +191,19 @@ pub fn CDPT(comptime TypeProvider: type) type {
|
|||||||
// Stagehand parses the response and error if we don't return a
|
// Stagehand parses the response and error if we don't return a
|
||||||
// correct one for this call.
|
// correct one for this call.
|
||||||
if (std.mem.eql(u8, method, "Page.getFrameTree")) {
|
if (std.mem.eql(u8, method, "Page.getFrameTree")) {
|
||||||
// If a real page already exists (connectOverCDP flow), return
|
// If we have a brower context and a target id, we can call the
|
||||||
// its actual frame ID so that subsequent lifecycle events
|
// real dispatch command, even during STARTUP.
|
||||||
// (frameNavigated, etc.) match the driver's frame tracking.
|
|
||||||
if (command.cdp.browser_context) |*bc| {
|
if (command.cdp.browser_context) |*bc| {
|
||||||
if (bc.target_id) |*target_id| {
|
if (bc.target_id != null) {
|
||||||
return command.sendResult(.{
|
return dispatchCommand(command, method);
|
||||||
.frameTree = .{
|
|
||||||
.frame = .{
|
|
||||||
.id = target_id,
|
|
||||||
.loaderId = "LOADERID24DD2FD56CF1EF33C965C79C",
|
|
||||||
.securityOrigin = URL_BASE,
|
|
||||||
.url = bc.getURL() orelse "about:blank",
|
|
||||||
.secureContextType = "Secure",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}, .{});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// No real page yet - return the synthetic STARTUP frame ID.
|
|
||||||
return command.sendResult(.{
|
return command.sendResult(.{
|
||||||
.frameTree = .{
|
.frameTree = .{
|
||||||
.frame = .{
|
.frame = .{
|
||||||
.id = "TID-STARTUP",
|
.id = "TID-STARTUP",
|
||||||
.loaderId = "LOADERID24DD2FD56CF1EF33C965C79C",
|
.loaderId = "LID-STARTUP",
|
||||||
.securityOrigin = URL_BASE,
|
.securityOrigin = URL_BASE,
|
||||||
.url = "about:blank",
|
.url = "about:blank",
|
||||||
.secureContextType = "Secure",
|
.secureContextType = "Secure",
|
||||||
@@ -1018,7 +1007,7 @@ test "cdp: STARTUP getFrameTree returns real frame ID when page exists" {
|
|||||||
.frameTree = .{
|
.frameTree = .{
|
||||||
.frame = .{
|
.frame = .{
|
||||||
.id = "TID-STARTUP",
|
.id = "TID-STARTUP",
|
||||||
.loaderId = "LOADERID24DD2FD56CF1EF33C965C79C",
|
.loaderId = "LID-STARTUP",
|
||||||
.url = "about:blank",
|
.url = "about:blank",
|
||||||
.secureContextType = "Secure",
|
.secureContextType = "Secure",
|
||||||
},
|
},
|
||||||
@@ -1028,15 +1017,23 @@ test "cdp: STARTUP getFrameTree returns real frame ID when page exists" {
|
|||||||
|
|
||||||
{
|
{
|
||||||
// browser context with target_id - should return real frame ID
|
// browser context with target_id - should return real frame ID
|
||||||
_ = try ctx.loadBrowserContext(.{ .target_id = "TID-000000000X".* });
|
const bc = try ctx.loadBrowserContext(.{ .target_id = "TID-000000000X".* });
|
||||||
try ctx.processMessage(.{ .id = 2, .method = "Page.getFrameTree", .sessionId = "STARTUP" });
|
try ctx.processMessage(.{ .id = 2, .method = "Page.getFrameTree", .sessionId = "STARTUP" });
|
||||||
try ctx.expectSentResult(.{
|
try ctx.expectSentResult(.{
|
||||||
.frameTree = .{
|
.frameTree = .{
|
||||||
.frame = .{
|
.frame = .{
|
||||||
.id = "TID-000000000X",
|
.id = "TID-000000000X",
|
||||||
.loaderId = "LOADERID24DD2FD56CF1EF33C965C79C",
|
.loaderId = "LID-0000000001",
|
||||||
.url = "about:blank",
|
.url = "about:blank",
|
||||||
.secureContextType = "Secure",
|
.domainAndRegistry = "",
|
||||||
|
.securityOrigin = bc.security_origin,
|
||||||
|
.mimeType = "text/html",
|
||||||
|
.adFrameStatus = .{
|
||||||
|
.adFrameType = "none",
|
||||||
|
},
|
||||||
|
.secureContextType = bc.secure_context_type,
|
||||||
|
.crossOriginIsolatedContextType = "NotIsolated",
|
||||||
|
.gatedAPIFeatures = [_][]const u8{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, .{ .id = 2, .session_id = "STARTUP" });
|
}, .{ .id = 2, .session_id = "STARTUP" });
|
||||||
|
|||||||
Reference in New Issue
Block a user