cdp: fix some id inconsitency accross runtime messages

This commit is contained in:
Pierre Tachoire
2024-12-18 16:54:01 +01:00
parent bcaace1c91
commit 8e2cb36597
4 changed files with 13 additions and 10 deletions

View File

@@ -121,6 +121,7 @@ pub fn dispatch(
pub const State = struct {
executionContextId: u32 = 0,
contextID: ?[]const u8 = null,
sessionID: ?[]const u8 = null,
frameID: []const u8 = FrameID,
url: []const u8 = URLBase,
securityOrigin: []const u8 = URLBase,

View File

@@ -129,13 +129,11 @@ fn sendInspector(
}
}
ctx.sendInspector(msg.json);
if (method == .enable) {
try executionContextCreated(
alloc,
ctx,
0,
1,
"://",
"",
// TODO: hard coded ID
@@ -147,10 +145,12 @@ fn sendInspector(
.frameId = cdp.FrameID,
},
// TODO: hard coded ID
target.BrowserContextID,
msg.sessionId orelse target.BrowserContextID,
);
}
ctx.sendInspector(msg.json);
if (msg.id == null) return "";
return result(alloc, msg.id.?, null, null, msg.sessionId);

View File

@@ -138,7 +138,7 @@ fn setAutoAttach(
.sessionId = cdp.BrowserSessionID,
.targetInfo = .{
.targetId = PageTargetID,
.title = "New Incognito tab",
.title = "about:blank",
.url = cdp.URLBase,
.browserContextId = BrowserContextID,
},
@@ -171,8 +171,8 @@ fn attachToTarget(
const attached = AttachToTarget{
.sessionId = cdp.BrowserSessionID,
.targetInfo = .{
.targetId = PageTargetID,
.title = "New Incognito tab",
.targetId = input.params.targetId,
.title = "about:blank",
.url = cdp.URLBase,
.browserContextId = BrowserContextID,
},
@@ -185,7 +185,7 @@ fn attachToTarget(
sessionId: []const u8,
};
const output = SessionId{
.sessionId = input.sessionId orelse BrowserContextID,
.sessionId = input.sessionId orelse cdp.BrowserSessionID,
};
return result(alloc, input.id, SessionId, output, null);
}
@@ -342,6 +342,7 @@ fn createTarget(
ctx.state.securityOrigin = "://";
ctx.state.secureContextType = "InsecureScheme";
ctx.state.loaderID = LoaderID;
ctx.state.sessionID = msg.sessionId;
// send targetCreated event
const created = TargetCreated{
@@ -361,9 +362,10 @@ fn createTarget(
.sessionId = cdp.ContextSessionID,
.targetInfo = .{
.targetId = ctx.state.frameID,
.title = "",
.title = "about:blank",
.url = ctx.state.url,
.browserContextId = input.params.browserContextId orelse ContextID,
.attached = true,
},
.waitingForDebugger = true,
};

View File

@@ -347,7 +347,7 @@ pub const Ctx = struct {
const s = try std.fmt.allocPrint(
allocator,
tpl,
.{ msg_open, cdp.ContextSessionID },
.{ msg_open, ctx.state.sessionID orelse cdp.ContextSessionID },
);
try ctx.send(s);