From 04487b6b9182c9393ae3fe82945484b4c03252a7 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Mon, 8 Sep 2025 12:07:48 +0200 Subject: [PATCH] cdp: allow double isolated world with same world name In this case we reuse the existing isolated world and isolated context and we log a warning --- src/cdp/cdp.zig | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/cdp/cdp.zig b/src/cdp/cdp.zig index d8878bdc..6dec217b 100644 --- a/src/cdp/cdp.zig +++ b/src/cdp/cdp.zig @@ -428,7 +428,20 @@ pub fn BrowserContext(comptime CDP_T: type) type { pub fn createIsolatedWorld(self: *Self, world_name: []const u8, grant_universal_access: bool) !*IsolatedWorld { if (self.isolated_world != null) { - return error.CurrentlyOnly1IsolatedWorldSupported; + // if the two world have different names, be safe and return an + // error. + if (std.mem.eql(u8, self.isolated_world.?.name, world_name) == false) { + return error.CurrentlyOnly1IsolatedWorldSupported; + } + + // If the two worlds have the same name, reuse the existing one + // but send a warning. + log.warn(.cdp, "not implemented", .{ + .feature = "createIsolatedWorld: Not implemented second isolated world creation", + .info = "reuse existing isolated world with the same name", + .world_name = world_name, + }); + return &self.isolated_world.?; } var executor = try self.cdp.browser.env.newExecutionWorld(); @@ -682,7 +695,14 @@ const IsolatedWorld = struct { // This also means this pointer becomes invalid after removePage untill a new page is created. // Currently we have only 1 page/frame and thus also only 1 state in the isolate world. pub fn createContext(self: *IsolatedWorld, page: *Page) !void { - if (self.executor.js_context != null) return error.Only1IsolatedContextSupported; + // if (self.executor.js_context != null) return error.Only1IsolatedContextSupported; + if (self.executor.js_context != null) { + log.warn(.cdp, "not implemented", .{ + .feature = "createContext: Not implemented second isolated context creation", + .info = "reuse existing context", + }); + return; + } _ = try self.executor.createJsContext( &page.window, page,