mirror of
				https://github.com/lightpanda-io/browser.git
				synced 2025-10-29 15:13:28 +00:00 
			
		
		
		
	start inspector when the js env starts
This commit is contained in:
		| @@ -215,7 +215,9 @@ pub const Page = struct { | ||||
|     } | ||||
|  | ||||
|     // start js env. | ||||
|     pub fn start(self: *Page) !void { | ||||
|     // - auxData: extra data forwarded to the Inspector | ||||
|     // see Inspector.contextCreated | ||||
|     pub fn start(self: *Page, auxData: ?[]const u8) !void { | ||||
|         // start JS env | ||||
|         log.debug("start js env", .{}); | ||||
|         try self.session.env.start(); | ||||
| @@ -226,6 +228,15 @@ pub const Page = struct { | ||||
|         // add global objects | ||||
|         log.debug("setup global env", .{}); | ||||
|         try self.session.env.bindGlobal(&self.session.window); | ||||
|  | ||||
|         // load polyfills | ||||
|         try polyfill.load(self.arena.allocator(), self.session.env); | ||||
|  | ||||
|         // inspector | ||||
|         if (self.session.inspector) |inspector| { | ||||
|             log.debug("inspector context created", .{}); | ||||
|             inspector.contextCreated(self.session.env, "", self.origin orelse "://", auxData); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     // reset js env and mem arena. | ||||
| @@ -387,9 +398,6 @@ pub const Page = struct { | ||||
|  | ||||
|         // https://html.spec.whatwg.org/#read-html | ||||
|  | ||||
|         // load polyfills | ||||
|         try polyfill.load(alloc, self.session.env); | ||||
|  | ||||
|         // inspector | ||||
|         if (self.session.inspector) |inspector| { | ||||
|             inspector.contextCreated(self.session.env, "", self.origin.?, auxData); | ||||
|   | ||||
| @@ -351,8 +351,16 @@ fn createTarget( | ||||
|  | ||||
|     // create the page | ||||
|     const p = try ctx.browser.session.createPage(); | ||||
|     ctx.state.executionContextId += 1; | ||||
|     // start the js env | ||||
|     try p.start(); | ||||
|     const auxData = try std.fmt.allocPrint( | ||||
|         alloc, | ||||
|         // NOTE: we assume this is the default web page | ||||
|         "{{\"isDefault\":true,\"type\":\"default\",\"frameId\":\"{s}\"}}", | ||||
|         .{ctx.state.frameID}, | ||||
|     ); | ||||
|     defer alloc.free(auxData); | ||||
|     try p.start(auxData); | ||||
|  | ||||
|     // send targetCreated event | ||||
|     const created = TargetCreated{ | ||||
|   | ||||
| @@ -326,7 +326,7 @@ pub fn main() !void { | ||||
|  | ||||
|             // page | ||||
|             const page = try browser.session.createPage(); | ||||
|             try page.start(); | ||||
|             try page.start(null); | ||||
|             defer page.end(); | ||||
|  | ||||
|             _ = page.navigate(opts.url, null) catch |err| switch (err) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Pierre Tachoire
					Pierre Tachoire