mirror of
				https://github.com/lightpanda-io/browser.git
				synced 2025-10-28 22:53:28 +00:00 
			
		
		
		
	Merge pull request #391 from lightpanda-io/cdp-ctx-sessionid
	
		
			
	
		
	
	
		
	
		
			Some checks are pending
		
		
	
	
		
			
				
	
				wpt / web platform tests (push) Waiting to run
				
			
		
			
				
	
				wpt / perf-fmt (push) Blocked by required conditions
				
			
		
			
				
	
				zig-test / zig build dev (push) Waiting to run
				
			
		
			
				
	
				zig-test / zig build release (push) Waiting to run
				
			
		
			
				
	
				zig-test / zig test (push) Waiting to run
				
			
		
			
				
	
				zig-test / perf-fmt (push) Blocked by required conditions
				
			
		
			
				
	
				zig-test / demo-puppeteer (push) Blocked by required conditions
				
			
		
		
	
	
				
					
				
			
		
			Some checks are pending
		
		
	
	wpt / web platform tests (push) Waiting to run
				
			wpt / perf-fmt (push) Blocked by required conditions
				
			zig-test / zig build dev (push) Waiting to run
				
			zig-test / zig build release (push) Waiting to run
				
			zig-test / zig test (push) Waiting to run
				
			zig-test / perf-fmt (push) Blocked by required conditions
				
			zig-test / demo-puppeteer (push) Blocked by required conditions
				
			cdp: use an enum for SessionID
This commit is contained in:
		| @@ -121,7 +121,7 @@ pub fn dispatch( | ||||
| pub const State = struct { | ||||
|     executionContextId: u32 = 0, | ||||
|     contextID: ?[]const u8 = null, | ||||
|     sessionID: ?[]const u8 = null, | ||||
|     sessionID: SessionID = .CONTEXTSESSIONID0497A05C95417CF4, | ||||
|     frameID: []const u8 = FrameID, | ||||
|     url: []const u8 = URLBase, | ||||
|     securityOrigin: []const u8 = URLBase, | ||||
| @@ -225,8 +225,21 @@ pub fn sendEvent( | ||||
| // ------ | ||||
|  | ||||
| // TODO: hard coded IDs | ||||
| pub const BrowserSessionID = "BROWSERSESSIONID597D9875C664CAC0"; | ||||
| pub const ContextSessionID = "CONTEXTSESSIONID0497A05C95417CF4"; | ||||
| pub const SessionID = enum { | ||||
|     BROWSERSESSIONID597D9875C664CAC0, | ||||
|     CONTEXTSESSIONID0497A05C95417CF4, | ||||
|  | ||||
|     pub fn parse(str: []const u8) !SessionID { | ||||
|         inline for (@typeInfo(SessionID).Enum.fields) |enumField| { | ||||
|             if (std.mem.eql(u8, str, enumField.name)) { | ||||
|                 return @field(SessionID, enumField.name); | ||||
|             } | ||||
|         } | ||||
|         return error.InvalidSessionID; | ||||
|     } | ||||
| }; | ||||
| pub const BrowserSessionID = @tagName(SessionID.BROWSERSESSIONID597D9875C664CAC0); | ||||
| pub const ContextSessionID = @tagName(SessionID.CONTEXTSESSIONID0497A05C95417CF4); | ||||
| pub const URLBase = "chrome://newtab/"; | ||||
| pub const LoaderID = "LOADERID24DD2FD56CF1EF33C965C79C"; | ||||
| pub const FrameID = "FRAMEIDD8AED408A0467AC93100BCDBE"; | ||||
|   | ||||
| @@ -117,7 +117,12 @@ fn sendInspector( | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     ctx.state.sessionID = msg.sessionId; | ||||
|     if (msg.sessionId) |s| { | ||||
|         ctx.state.sessionID = cdp.SessionID.parse(s) catch |err| { | ||||
|             log.err("parse sessionID: {s} {any}", .{ s, err }); | ||||
|             return err; | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|     // remove awaitPromise true params | ||||
|     // TODO: delete when Promise are correctly handled by zig-js-runtime | ||||
|   | ||||
| @@ -344,7 +344,13 @@ fn createTarget( | ||||
|     ctx.state.securityOrigin = "://"; | ||||
|     ctx.state.secureContextType = "InsecureScheme"; | ||||
|     ctx.state.loaderID = LoaderID; | ||||
|     ctx.state.sessionID = msg.sessionId; | ||||
|  | ||||
|     if (msg.sessionId) |s| { | ||||
|         ctx.state.sessionID = cdp.SessionID.parse(s) catch |err| { | ||||
|             log.err("parse sessionID: {s} {any}", .{ s, err }); | ||||
|             return err; | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|     // TODO stop the previous page instead? | ||||
|     if (ctx.browser.session.page != null) return error.pageAlreadyExists; | ||||
|   | ||||
| @@ -348,7 +348,7 @@ pub const Ctx = struct { | ||||
|         const s = try std.fmt.allocPrint( | ||||
|             allocator, | ||||
|             tpl, | ||||
|             .{ msg_open, ctx.state.sessionID orelse cdp.ContextSessionID }, | ||||
|             .{ msg_open, @tagName(ctx.state.sessionID) }, | ||||
|         ); | ||||
|  | ||||
|         try ctx.send(s); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Pierre Tachoire
					Pierre Tachoire