Skip to content

Commit b0accfb

Browse files
committed
start inspector when the js env starts
1 parent 504ee74 commit b0accfb

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/browser/browser.zig

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,25 @@ pub const Page = struct {
196196
}
197197

198198
// start js env.
199-
pub fn start(self: *Page) !void {
199+
// - auxData: extra data forwarded to the Inspector
200+
// see Inspector.contextCreated
201+
pub fn start(self: *Page, auxData: ?[]const u8) !void {
200202
// start JS env
201203
log.debug("start js env", .{});
202204
try self.session.env.start();
203205

204206
// add global objects
205207
log.debug("setup global env", .{});
206208
try self.session.env.bindGlobal(&self.session.window);
209+
210+
// load polyfills
211+
try polyfill.load(self.arena.allocator(), self.session.env);
212+
213+
// inspector
214+
if (self.session.inspector) |inspector| {
215+
log.debug("inspector context created", .{});
216+
inspector.contextCreated(self.session.env, "", self.origin orelse "://", auxData);
217+
}
207218
}
208219

209220
// reset js env and mem arena.
@@ -360,9 +371,6 @@ pub const Page = struct {
360371

361372
// https://html.spec.whatwg.org/#read-html
362373

363-
// load polyfills
364-
try polyfill.load(alloc, self.session.env);
365-
366374
// inspector
367375
if (self.session.inspector) |inspector| {
368376
inspector.contextCreated(self.session.env, "", self.origin.?, auxData);

src/cdp/target.zig

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,16 @@ fn createTarget(
336336

337337
// create the page
338338
const p = try ctx.browser.session.createPage();
339+
ctx.state.executionContextId += 1;
339340
// start the js env
340-
try p.start();
341+
const auxData = try std.fmt.allocPrint(
342+
alloc,
343+
// NOTE: we assume this is the default web page
344+
"{{\"isDefault\":true,\"type\":\"default\",\"frameId\":\"{s}\"}}",
345+
.{ctx.state.frameID},
346+
);
347+
defer alloc.free(auxData);
348+
try p.start(auxData);
341349

342350
// send attachToTarget event
343351
const attached = AttachToTarget{

src/main.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ pub fn main() !void {
326326

327327
// page
328328
const page = try browser.session.createPage();
329-
try page.start();
329+
try page.start(null);
330330
defer page.end();
331331

332332
_ = page.navigate(opts.url, null) catch |err| switch (err) {

0 commit comments

Comments
 (0)