@@ -97,36 +97,27 @@ fn addScriptToEvaluateOnNewDocument(cmd: anytype) !void {
9797 }, .{});
9898}
9999
100- // TODO: hard coded method
101100fn createIsolatedWorld (cmd : anytype ) ! void {
102- _ = cmd .browser_context orelse return error .BrowserContextNotLoaded ;
103-
104- const session_id = cmd .input .session_id orelse return error .SessionIdRequired ;
105-
106101 const params = (try cmd .params (struct {
107102 frameId : []const u8 ,
108103 worldName : []const u8 ,
109104 grantUniveralAccess : bool ,
110105 })) orelse return error .InvalidParams ;
106+ if (! params .grantUniveralAccess ) {
107+ std .debug .print ("grantUniveralAccess == false is not yet implemented" , .{});
108+ // When grantUniveralAccess == false and the client attempts to resolve
109+ // or otherwise access a DOM or other JS Object from another context that should fail.
110+ }
111+ const bc = cmd .browser_context orelse return error .BrowserContextNotLoaded ;
111112
112- // noop executionContextCreated event
113- try cmd .sendEvent ("Runtime.executionContextCreated" , .{
114- .context = runtime.ExecutionContextCreated {
115- .id = 0 ,
116- .origin = "" ,
117- .name = params .worldName ,
118- // TODO: hard coded ID
119- .uniqueId = "7102379147004877974.3265385113993241162" ,
120- .auxData = .{
121- .isDefault = false ,
122- .type = "isolated" ,
123- .frameId = params .frameId ,
124- },
125- },
126- }, .{ .session_id = session_id });
113+ try bc .createIsolatedWorld (params .worldName , params .grantUniveralAccess ); // orelse return error.IsolatedWorldAlreadyExists;
114+
115+ // Create the auxdata json from
116+ const aux_json = try std .fmt .allocPrint (cmd .arena , "{{\" isDefault\" :false,\" type\" :\" isolated\" ,\" frameId\" :\" {s}\" }}" , .{params .frameId });
117+ bc .session .inspector .contextCreated (bc .isolated_world .? .executor , bc .isolated_world .? .name , "" , aux_json , false );
127118
128119 return cmd .sendResult (.{
129- .executionContextId = 0 ,
120+ .executionContextId = bc . isolated_world .? . executor . context . debugContextId () ,
130121 }, .{});
131122}
132123
@@ -222,7 +213,24 @@ pub fn pageNavigate(bc: anytype, event: *const Notification.PageNavigate) !void
222213
223214 // Send Runtime.executionContextsCleared event
224215 // TODO: noop event, we have no env context at this point, is it necesarry?
216+ // When we actually recreated the context we should have the inspector send this event, see: resetContextGroup
225217 try cdp .sendEvent ("Runtime.executionContextsCleared" , null , .{ .session_id = session_id });
218+
219+ if (bc .isolated_world != null ) {
220+ const aux_json = try std .fmt .allocPrint (
221+ bc .session .arena .allocator (), // TODO change this
222+ "{{\" isDefault\" :false,\" type\" :\" isolated\" ,\" frameId\" :\" {s}\" }}" ,
223+ .{bc .target_id .? }, // TODO check this
224+ );
225+
226+ bc .session .inspector .contextCreated (
227+ bc .isolated_world .? .executor ,
228+ bc .isolated_world .? .name ,
229+ "://" ,
230+ aux_json ,
231+ false ,
232+ );
233+ }
226234}
227235
228236pub fn pageNavigated (bc : anytype , event : * const Notification.PageNavigated ) ! void {
0 commit comments