Repository navigation
feat(frame): add isolated worlds to evaluate JavaScript hidden from the page - #670
Merged
Merged
Conversation
…he page page.isolated_world(name) and frame.isolated_world(name) return an IsolatedWorld with the frame's evaluation methods, running in a world created with Page.createIsolatedWorld, the same one evaluate_on_new_document(world_name:) uses. Only the default execution context sets the frame's execution_id now, named isolated ones go to their world.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
page.evaluate_on_new_document(source, world_name:)could inject a script into an isolated world, but nothing let you evaluate in that world afterwards or create one on demand.Changes
Ferrum::IsolatedWorldincludesFrame::Runtime, so it has the sameevaluate,evaluate_async,execute,evaluate_funcandevaluate_onas a frame, with its own execution context.Page.createIsolatedWorldwhen the current document has none for that name. Chrome returns the same context for the same name, so it's the worldevaluate_on_new_document(world_name:)runs in.Frame#isolated_world(name)andFrame#isolated_worlds.PageandBrowserdelegateisolated_worldto the main frame.Runtime.executionContextCreatedchecksauxData.isDefault: only the default context sets the frame'sexecution_id, named isolated contexts go to their world. Destroyed and cleared contexts clear world ids too, so a world starts empty in a new document while the object stays usable.DOM.resolveNodewithexecutionContextId), so page nodes can be passed in and nodes come back.Test
spec/isolated_world_spec.rb: separate globals with a shared DOM, the world ofevaluate_on_new_document(world_name:), a fresh world after navigation, nodes in and out, and a world in an iframe.