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
|
||||
// correct one for this call.
|
||||
if (std.mem.eql(u8, method, "Page.getFrameTree")) {
|
||||
// If a real page already exists (connectOverCDP flow), return
|
||||
// its actual frame ID so that subsequent lifecycle events
|
||||
// (frameNavigated, etc.) match the driver's frame tracking.
|
||||
// If we have a brower context and a target id, we can call the
|
||||
// real dispatch command, even during STARTUP.
|
||||
if (command.cdp.browser_context) |*bc| {
|
||||
if (bc.target_id) |*target_id| {
|
||||
return command.sendResult(.{
|
||||
.frameTree = .{
|
||||
.frame = .{
|
||||
.id = target_id,
|
||||
.loaderId = "LOADERID24DD2FD56CF1EF33C965C79C",
|
||||
.securityOrigin = URL_BASE,
|
||||
.url = bc.getURL() orelse "about:blank",
|
||||
.secureContextType = "Secure",
|
||||
},
|
||||
},
|
||||
}, .{});
|
||||
if (bc.target_id != null) {
|
||||
return dispatchCommand(command, method);
|
||||
}
|
||||
}
|
||||
// No real page yet - return the synthetic STARTUP frame ID.
|
||||
|
||||
return command.sendResult(.{
|
||||
.frameTree = .{
|
||||
.frame = .{
|
||||
.id = "TID-STARTUP",
|
||||
.loaderId = "LOADERID24DD2FD56CF1EF33C965C79C",
|
||||
.loaderId = "LID-STARTUP",
|
||||
.securityOrigin = URL_BASE,
|
||||
.url = "about:blank",
|
||||
.secureContextType = "Secure",
|
||||
@@ -1018,7 +1007,7 @@ test "cdp: STARTUP getFrameTree returns real frame ID when page exists" {
|
||||
.frameTree = .{
|
||||
.frame = .{
|
||||
.id = "TID-STARTUP",
|
||||
.loaderId = "LOADERID24DD2FD56CF1EF33C965C79C",
|
||||
.loaderId = "LID-STARTUP",
|
||||
.url = "about:blank",
|
||||
.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
|
||||
_ = 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.expectSentResult(.{
|
||||
.frameTree = .{
|
||||
.frame = .{
|
||||
.id = "TID-000000000X",
|
||||
.loaderId = "LOADERID24DD2FD56CF1EF33C965C79C",
|
||||
.loaderId = "LID-0000000001",
|
||||
.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" });
|
||||
|
||||
Reference in New Issue
Block a user