Skip to content

Commit 4f149da

Browse files
committed
start inspector when the js env starts
1 parent 8a76083 commit 4f149da

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
@@ -199,14 +199,25 @@ pub const Page = struct {
199199
}
200200

201201
// start js env.
202-
pub fn start(self: *Page) !void {
202+
// - auxData: extra data forwarded to the Inspector
203+
// see Inspector.contextCreated
204+
pub fn start(self: *Page, auxData: ?[]const u8) !void {
203205
// start JS env
204206
log.debug("start js env", .{});
205207
try self.session.env.start();
206208

207209
// add global objects
208210
log.debug("setup global env", .{});
209211
try self.session.env.bindGlobal(&self.session.window);
212+
213+
// load polyfills
214+
try polyfill.load(self.arena.allocator(), self.session.env);
215+
216+
// inspector
217+
if (self.session.inspector) |inspector| {
218+
log.debug("inspector context created", .{});
219+
inspector.contextCreated(self.session.env, "", self.origin orelse "://", auxData);
220+
}
210221
}
211222

212223
// reset js env and mem arena.
@@ -368,9 +379,6 @@ pub const Page = struct {
368379

369380
// https://html.spec.whatwg.org/#read-html
370381

371-
// load polyfills
372-
try polyfill.load(alloc, self.session.env);
373-
374382
// inspector
375383
if (self.session.inspector) |inspector| {
376384
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
@@ -351,8 +351,16 @@ fn createTarget(
351351

352352
// create the page
353353
const p = try ctx.browser.session.createPage();
354+
ctx.state.executionContextId += 1;
354355
// start the js env
355-
try p.start();
356+
const auxData = try std.fmt.allocPrint(
357+
alloc,
358+
// NOTE: we assume this is the default web page
359+
"{{\"isDefault\":true,\"type\":\"default\",\"frameId\":\"{s}\"}}",
360+
.{ctx.state.frameID},
361+
);
362+
defer alloc.free(auxData);
363+
try p.start(auxData);
356364

357365
// send targetCreated event
358366
const created = TargetCreated{

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)