Skip to content

Commit 1b9bdaa

Browse files
committed
cdp: fix some id inconsitency accross runtime messages
1 parent 1a8fccf commit 1b9bdaa

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

src/cdp/cdp.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ pub fn do(
100100
pub const State = struct {
101101
executionContextId: u32 = 0,
102102
contextID: ?[]const u8 = null,
103+
sessionID: ?[]const u8 = null,
103104
frameID: []const u8 = FrameID,
104105
url: []const u8 = URLBase,
105106
securityOrigin: []const u8 = URLBase,

src/cdp/runtime.zig

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ fn sendInspector(
117117
}
118118
}
119119

120+
ctx.state.sessionID = msg.sessionId;
121+
120122
// remove awaitPromise true params
121123
// TODO: delete when Promise are correctly handled by zig-js-runtime
122124
if (method == .callFunctionOn or method == .evaluate) {
@@ -129,13 +131,11 @@ fn sendInspector(
129131
}
130132
}
131133

132-
ctx.sendInspector(msg.json);
133-
134134
if (method == .enable) {
135135
try executionContextCreated(
136136
alloc,
137137
ctx,
138-
0,
138+
1,
139139
"://",
140140
"",
141141
// TODO: hard coded ID
@@ -147,10 +147,12 @@ fn sendInspector(
147147
.frameId = cdp.FrameID,
148148
},
149149
// TODO: hard coded ID
150-
target.BrowserContextID,
150+
msg.sessionId orelse target.BrowserContextID,
151151
);
152152
}
153153

154+
ctx.sendInspector(msg.json);
155+
154156
return "";
155157
}
156158

src/cdp/target.zig

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ fn setAutoAttach(
123123
.sessionId = cdp.BrowserSessionID,
124124
.targetInfo = .{
125125
.targetId = PageTargetID,
126-
.title = "New Incognito tab",
126+
.title = "about:blank",
127127
.url = cdp.URLBase,
128128
.browserContextId = BrowserContextID,
129129
},
@@ -156,8 +156,8 @@ fn attachToTarget(
156156
const attached = AttachToTarget{
157157
.sessionId = cdp.BrowserSessionID,
158158
.targetInfo = .{
159-
.targetId = PageTargetID,
160-
.title = "New Incognito tab",
159+
.targetId = input.params.targetId,
160+
.title = "about:blank",
161161
.url = cdp.URLBase,
162162
.browserContextId = BrowserContextID,
163163
},
@@ -170,7 +170,7 @@ fn attachToTarget(
170170
sessionId: []const u8,
171171
};
172172
const output = SessionId{
173-
.sessionId = input.sessionId orelse BrowserContextID,
173+
.sessionId = input.sessionId orelse cdp.BrowserSessionID,
174174
};
175175
return result(alloc, input.id, SessionId, output, null);
176176
}
@@ -327,15 +327,17 @@ fn createTarget(
327327
ctx.state.securityOrigin = "://";
328328
ctx.state.secureContextType = "InsecureScheme";
329329
ctx.state.loaderID = LoaderID;
330+
ctx.state.sessionID = msg.sessionId;
330331

331332
// send attachToTarget event
332333
const attached = AttachToTarget{
333334
.sessionId = cdp.ContextSessionID,
334335
.targetInfo = .{
335336
.targetId = ctx.state.frameID,
336-
.title = "",
337+
.title = "about:blank",
337338
.url = ctx.state.url,
338339
.browserContextId = input.params.browserContextId orelse ContextID,
340+
.attached = true,
339341
},
340342
.waitingForDebugger = true,
341343
};

src/server.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ pub const Ctx = struct {
347347
const s = try std.fmt.allocPrint(
348348
allocator,
349349
tpl,
350-
.{ msg_open, cdp.ContextSessionID },
350+
.{ msg_open, ctx.state.sessionID orelse cdp.ContextSessionID },
351351
);
352352

353353
try ctx.send(s);

0 commit comments

Comments
 (0)