@@ -331,7 +331,7 @@ pub fn BrowserContext(comptime CDP_T: type) type {
331
331
node_search_list : Node.Search.List ,
332
332
333
333
inspector : Inspector ,
334
- isolated_world : ? IsolatedWorld ,
334
+ isolated_worlds : std . ArrayListUnmanaged ( IsolatedWorld ) ,
335
335
336
336
http_proxy_changed : bool = false ,
337
337
@@ -375,7 +375,7 @@ pub fn BrowserContext(comptime CDP_T: type) type {
375
375
.page_life_cycle_events = false , // TODO; Target based value
376
376
.node_registry = registry ,
377
377
.node_search_list = undefined ,
378
- .isolated_world = null ,
378
+ .isolated_worlds = .empty ,
379
379
.inspector = inspector ,
380
380
.notification_arena = cdp .notification_arena .allocator (),
381
381
.intercept_state = try InterceptState .init (allocator ),
@@ -404,9 +404,10 @@ pub fn BrowserContext(comptime CDP_T: type) type {
404
404
// so we need to shutdown the page one first.
405
405
self .cdp .browser .closeSession ();
406
406
407
- if (self .isolated_world ) | * world | {
407
+ for (self .isolated_worlds . items ) | * world | {
408
408
world .deinit ();
409
409
}
410
+ self .isolated_worlds .clearRetainingCapacity ();
410
411
self .node_registry .deinit ();
411
412
self .node_search_list .deinit ();
412
413
self .cdp .browser .notification .unregisterAll (self );
@@ -427,32 +428,19 @@ pub fn BrowserContext(comptime CDP_T: type) type {
427
428
}
428
429
429
430
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
-
447
431
var executor = try self .cdp .browser .env .newExecutionWorld ();
448
432
errdefer executor .deinit ();
449
433
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 ,
452
439
.executor = executor ,
453
440
.grant_universal_access = grant_universal_access ,
454
441
};
455
- return & self .isolated_world .? ;
442
+
443
+ return world ;
456
444
}
457
445
458
446
pub fn nodeWriter (self : * Self , root : * const Node , opts : Node.Writer.Opts ) Node.Writer {
@@ -711,6 +699,14 @@ const IsolatedWorld = struct {
711
699
Env .GlobalMissingCallback .init (& self .polyfill_loader ),
712
700
);
713
701
}
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
+ }
714
710
};
715
711
716
712
// This is a generic because when we send a result we have two different
0 commit comments