Repository navigation
fix: run extensions before page scripts in popups and out-of-process iframes - #663
Merged
Merged
Conversation
…wser.add_extension Browser#evaluate_on_new_document only appended to the extensions list, so it reached pages built afterwards and not the page you called it on. It's now a Page method sending Page.addScriptToEvaluateOnNewDocument, with world_name: and run_immediately:, returning the id for remove_script_on_new_document. browser.add_extension takes over adding to the list. Extension files are read in Browser.new and add_extension, so a missing file raises right there.
Pages were resumed on attach before Page.addScriptToEvaluateOnNewDocument was sent, so a popup's first document loaded without extensions and Runtime.evaluate applied them only after load, out-of-process iframes never got them. Register them on the attach session before resuming and drop the Runtime.evaluate fallback. An out-of-process iframe ignores the scripts until Page is enabled on its session, so it's enabled first when there are extensions.
When Target.targetCreated for an iframe arrived before Target.attachedToTarget, the target took its frame owner's session and the attached one was ignored, so commands sent through the iframe target reached the parent page. The session from Target.attachedToTarget now always wins.
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.
Extensions didn't run before a page's own scripts everywhere:
Page.addScriptToEvaluateOnNewDocumentwas sent. Its first document loaded without extensions, and theRuntime.evaluatefallback applied them only after load.about:blank, through the sameRuntime.evaluatefallback.Changes
Pageis enabled on its session, soPage.enableis sent first when there are extensions. TheRuntime.evaluatefallback is gone.Page#evaluate_on_new_document(source, world_name:, run_immediately:)is now a plainPage.addScriptToEvaluateOnNewDocumentcall on that page. It returns the script id, andPage#remove_script_on_new_documentremoves it.browser.evaluate_on_new_documentgoes to the current page like other page methods.browser.add_extensionadds an extension for pages and iframes attached afterwards. That's whatbrowser.evaluate_on_new_documentused to do.Browser.newandadd_extension, so a missing file raisesErrno::ENOENTthere instead of on first navigation.Breaking
Code that relied on
browser.evaluate_on_new_documentreaching pages opened later should usebrowser.add_extension.