@@ -331,7 +331,7 @@ pub fn BrowserContext(comptime CDP_T: type) type {
331331 node_search_list : Node.Search.List ,
332332
333333 inspector : Inspector ,
334- isolated_world : ? IsolatedWorld ,
334+ isolated_worlds : std . ArrayListUnmanaged ( IsolatedWorld ) ,
335335
336336 http_proxy_changed : bool = false ,
337337
@@ -375,7 +375,7 @@ pub fn BrowserContext(comptime CDP_T: type) type {
375375 .page_life_cycle_events = false , // TODO; Target based value
376376 .node_registry = registry ,
377377 .node_search_list = undefined ,
378- .isolated_world = null ,
378+ .isolated_worlds = .empty ,
379379 .inspector = inspector ,
380380 .notification_arena = cdp .notification_arena .allocator (),
381381 .intercept_state = try InterceptState .init (allocator ),
@@ -404,9 +404,10 @@ pub fn BrowserContext(comptime CDP_T: type) type {
404404 // so we need to shutdown the page one first.
405405 self .cdp .browser .closeSession ();
406406
407- if (self .isolated_world ) | * world | {
407+ for (self .isolated_worlds . items ) | * world | {
408408 world .deinit ();
409409 }
410+ self .isolated_worlds .clearRetainingCapacity ();
410411 self .node_registry .deinit ();
411412 self .node_search_list .deinit ();
412413 self .cdp .browser .notification .unregisterAll (self );
@@ -427,32 +428,19 @@ pub fn BrowserContext(comptime CDP_T: type) type {
427428 }
428429
429430 pub fn createIsolatedWorld (self : * Self , world_name : []const u8 , grant_universal_access : bool ) ! * IsolatedWorld {
430- if (self .isolated_world != null ) {
431- // if the two world have different names, be safe and return an
432- // error.
433- if (std .mem .eql (u8 , self .isolated_world .? .name , world_name ) == false ) {
434- return error .CurrentlyOnly1IsolatedWorldSupported ;
435- }
436-
437- // If the two worlds have the same name, reuse the existing one
438- // but send a warning.
439- log .warn (.cdp , "not implemented" , .{
440- .feature = "createIsolatedWorld: Not implemented second isolated world creation" ,
441- .info = "reuse existing isolated world with the same name" ,
442- .world_name = world_name ,
443- });
444- return & self .isolated_world .? ;
445- }
446-
447431 var executor = try self .cdp .browser .env .newExecutionWorld ();
448432 errdefer executor .deinit ();
449433
450- self .isolated_world = .{
451- .name = try self .arena .dupe (u8 , world_name ),
434+ const owned_name = try self .arena .dupe (u8 , world_name );
435+ const world = try self .isolated_worlds .addOne (self .arena );
436+
437+ world .* = .{
438+ .name = owned_name ,
452439 .executor = executor ,
453440 .grant_universal_access = grant_universal_access ,
454441 };
455- return & self .isolated_world .? ;
442+
443+ return world ;
456444 }
457445
458446 pub fn nodeWriter (self : * Self , root : * const Node , opts : Node.Writer.Opts ) Node.Writer {
@@ -711,6 +699,14 @@ const IsolatedWorld = struct {
711699 Env .GlobalMissingCallback .init (& self .polyfill_loader ),
712700 );
713701 }
702+
703+ pub fn createContextAndLoadPolyfills (self : * IsolatedWorld , arena : Allocator , page : * Page ) ! void {
704+ // We need to recreate the isolated world context
705+ try self .createContext (page );
706+
707+ const loader = @import ("../browser/polyfill/polyfill.zig" );
708+ try loader .preload (arena , & self .executor .js_context .? );
709+ }
714710};
715711
716712// This is a generic because when we send a result we have two different
0 commit comments