Skip to content

CDP: create an context per isolated world per frame - #3397

Open
karlseguin wants to merge 3 commits into
mainfrom
isolatedworld-frames
Open

CDP: create an context per isolated world per frame#3397
karlseguin wants to merge 3 commits into
mainfrom
isolatedworld-frames

Conversation

@karlseguin

@karlseguin karlseguin commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Previously, we created a single context per isolated world for the main frame. We now create an isolate world per frame.

Fixes: #3347 & #2400

Previously, we created a single context per isolated world for the main frame.
We now create an isolate world per frame.

Fixes: #3347
@krichprollsch

Copy link
Copy Markdown
Member

Does it impact #2400?

Previously, we had a single root-bound context which we'd re-announce for every
frame. Now, Page.createIsolatedWorld and addScriptToEvaluateOnNewDocument seed
the context per frame(s).
@karlseguin
karlseguin marked this pull request as ready for review September 4, 2026 03:03
@karlseguin

Copy link
Copy Markdown
Collaborator Author

Does it impact #2400?

Yes, with the last commit, I believe both issues will be fixed. Worth pointing out that this will increase memory when iframes are loaded (for drivers that use this, which Puppeteer and Playwright do).

Comment thread src/server/cdp/domains/page.zig Outdated
Comment thread src/server/cdp/CDP.zig
// This ensures CDP inspector contexts don't share v8::Globals with main world.
// Shared by all of the world's frame contexts, like the main world shares
// Page.identity across frames, and reset with them on root teardown.
identity: js.Identity = .{},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it a problem having multiple frame context sharing the same identity map?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is why the identity map is stored on the page. Two frames in the same origin get the same v8::Object instance.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that did make me realize that we don't give the context an origin, so it keeps its opaque origin and never gets the correct SecurityToken. That's fixed now.

Comment thread src/server/cdp/CDP.zig
Comment thread src/server/cdp/domains/dom.zig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CDP: Page.createIsolatedWorld(childFrameId) evaluates the main document

2 participants