emit context created on createTarget event for chromedp

This commit is contained in:
Karl Seguin
2025-04-29 10:58:23 +08:00
parent 2d5ff8252c
commit 9044925f32
3 changed files with 7 additions and 4 deletions

View File

@@ -173,6 +173,10 @@ pub const Session = struct {
const page = &self.page.?;
try Page.init(page, page_arena.allocator(), self);
self.notify(&.{ .context_created = .{
.origin = try page.origin(),
} });
// start JS env
log.debug("start new js scope", .{});

View File

@@ -404,8 +404,8 @@ pub fn BrowserContext(comptime CDP_T: type) type {
const self: *Self = @alignCast(@ptrCast(ctx));
switch (notification.*) {
.context_created => |cc| {
const aux_data = try std.fmt.allocPrint(self.arena, "{{\"isDefault\":true,\"type\":\"default\",\"frameId\":\"{s}\"}}", .{self.target_id.?});
.context_created => |cc| if (self.target_id) |target_id| {
const aux_data = try std.fmt.allocPrint(self.arena, "{{\"isDefault\":true,\"type\":\"default\",\"frameId\":\"{s}\"}}", .{target_id});
self.inspector.contextCreated(
self.session.page.?.scope,
"",

View File

@@ -123,6 +123,7 @@ fn createTarget(cmd: anytype) !void {
const target_id = cmd.cdp.target_id_gen.next();
try bc.createIsolatedWorld();
bc.target_id = target_id;
_ = try bc.session.createPage();
@@ -149,8 +150,6 @@ fn createTarget(cmd: anytype) !void {
try doAttachtoTarget(cmd, target_id);
}
bc.target_id = target_id;
try cmd.sendResult(.{
.targetId = target_id,
}, .{});