mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
cdp: allow multiple calls to attachToTarget
Playwright, when creating a new CDPSession, sends an attachToBrowserTarget followed by another attachToTarget to re-attach itself to the existing target. see playwright/axtree.js from demo/ repository.
This commit is contained in:
@@ -243,9 +243,7 @@ fn attachToTarget(cmd: anytype) !void {
|
|||||||
return error.UnknownTargetId;
|
return error.UnknownTargetId;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bc.session_id == null) {
|
try doAttachtoTarget(cmd, target_id);
|
||||||
try doAttachtoTarget(cmd, target_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return cmd.sendResult(
|
return cmd.sendResult(
|
||||||
.{ .sessionId = bc.session_id },
|
.{ .sessionId = bc.session_id },
|
||||||
@@ -451,22 +449,23 @@ fn setAutoAttach(cmd: anytype) !void {
|
|||||||
|
|
||||||
fn doAttachtoTarget(cmd: anytype, target_id: []const u8) !void {
|
fn doAttachtoTarget(cmd: anytype, target_id: []const u8) !void {
|
||||||
const bc = cmd.browser_context.?;
|
const bc = cmd.browser_context.?;
|
||||||
lp.assert(bc.session_id == null, "CDP.target.doAttachtoTarget not null session_id", .{});
|
const session_id = bc.session_id orelse cmd.cdp.session_id_gen.next();
|
||||||
const session_id = cmd.cdp.session_id_gen.next();
|
|
||||||
|
|
||||||
// extra_headers should not be kept on a new page or tab,
|
if (bc.session_id == null) {
|
||||||
// currently we have only 1 page, we clear it just in case
|
// extra_headers should not be kept on a new page or tab,
|
||||||
bc.extra_headers.clearRetainingCapacity();
|
// currently we have only 1 page, we clear it just in case
|
||||||
|
bc.extra_headers.clearRetainingCapacity();
|
||||||
|
}
|
||||||
|
|
||||||
try cmd.sendEvent("Target.attachedToTarget", AttachToTarget{
|
try cmd.sendEvent("Target.attachedToTarget", AttachToTarget{
|
||||||
.sessionId = session_id,
|
.sessionId = session_id,
|
||||||
.targetInfo = TargetInfo{
|
.targetInfo = TargetInfo{
|
||||||
.targetId = target_id,
|
.targetId = target_id,
|
||||||
.title = "about:blank",
|
.title = bc.getTitle() orelse "about:blank",
|
||||||
.url = "chrome://newtab/",
|
.url = bc.getURL() orelse "chrome://newtab/",
|
||||||
.browserContextId = bc.id,
|
.browserContextId = bc.id,
|
||||||
},
|
},
|
||||||
}, .{});
|
}, .{ .session_id = bc.session_id });
|
||||||
|
|
||||||
bc.session_id = session_id;
|
bc.session_id = session_id;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user