From 7abb7277c93b4d116c1123a8a512aeb109d85666 Mon Sep 17 00:00:00 2001 From: Francis Bouvier Date: Wed, 12 Jun 2024 17:56:07 +0200 Subject: [PATCH] Fix call to Runtime.executionContextCreated in Page.navigate Signed-off-by: Francis Bouvier --- src/cdp/cdp.zig | 1 + src/cdp/page.zig | 39 +++++++++++++++------------------------ 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/cdp/cdp.zig b/src/cdp/cdp.zig index 036621d6..d8647a4a 100644 --- a/src/cdp/cdp.zig +++ b/src/cdp/cdp.zig @@ -94,6 +94,7 @@ pub fn do( } pub const State = struct { + executionContextId: u8 = 0, contextID: ?[]const u8 = null, frameID: []const u8 = FrameID, url: []const u8 = URLBase, diff --git a/src/cdp/page.zig b/src/cdp/page.zig index 2c1eddf1..1867e98c 100644 --- a/src/cdp/page.zig +++ b/src/cdp/page.zig @@ -225,13 +225,26 @@ fn navigate( std.log.debug("res {s}", .{res}); try server.sendSync(ctx, res); - // Runtime.executionContextsCleared event + // Send clear runtime contexts event (noop) try sendEvent(alloc, ctx, "Runtime.executionContextsCleared", void, {}, msg.sessionID); - // launch navigate + // Launch navigate var p = try ctx.browser.currentSession().createPage(); _ = try p.navigate(params.url); + // Send create runtime context event + ctx.state.executionContextId += 1; + try Runtime.executionContextCreated( + alloc, + ctx, + ctx.state.executionContextId, + "http://127.0.0.1:1234", // TODO: real domain + "", + "7102379147004877974.3265385113993241162", + .{ .frameId = ctx.state.frameID }, + msg.sessionID, + ); + // frameNavigated event const FrameNavigated = struct { frame: Frame, @@ -267,28 +280,6 @@ fn navigate( ); } - try Runtime.executionContextCreated( - alloc, - ctx, - 3, - "http://127.0.0.1:1234", - "", - "7102379147004877974.3265385113993241162", - .{ .frameId = ctx.state.frameID }, - msg.sessionID, - ); - - try Runtime.executionContextCreated( - alloc, - ctx, - 4, - "://", - "__playwright_utility_world__", - "-4572718120346458707.6016875269626438350", - .{ .isDefault = false, .type = "isolated", .frameId = ctx.state.frameID }, - msg.sessionID, - ); - // domContentEventFired event ts_event = .{ .timestamp = 343721.803338 }; try sendEvent(