Repository navigation
feat(browser): add on_page to set up every page before Ferrum hands it out - #735
Merged
Merged
Conversation
…t out
browser.on_page { |page| } registers a block, stored on the options like add_extension, that Target#build_page calls with each page it
builds, created or opened by another page, before returning it. Callers can subscribe to a page's events or configure it before anything
happens on it, without subclassing Page.
route
added a commit
to rubycdp/cuprite
that referenced
this pull request
Nov 26, 2026
… in the driver (#399) * chore(deps): build against Ferrum's on-page-hook branch until rubycdp/ferrum#735 is merged * ref(browser): set pages up through Ferrum's on_page instead of subclassing Ferrum::Page Cuprite::Page overrode Ferrum::Page's private subscribe and prepare_page, and attach_page built it through Target's private maybe_sleep_if_new_window and page=. Browser now registers one on_page block that sets every page up with Ferrum's public API, and keeps the frame stack and the dialog queue in a PageState per target. - Browser delegates the DOM and JavaScript methods to the frame switched to, and overrides go_to and set_viewport for the pending connections error and the scale_factor: and mobile: defaults - resize applies those defaults again, since Ferrum's Page#resize sets the viewport without them - An unhandled dialog's error is raised around the Driver and Node calls instead of around every page command * chore(deps): build against Ferrum main again now that rubycdp/ferrum#735 and #736 are merged * ref(driver): drive a plain Ferrum browser and keep Capybara's windows in the driver Cuprite::Browser subclassed Ferrum::Browser to keep the current window, the per-page frames and dialogs, the settings and the page setup. The driver keeps them now, so driver.browser is a plain Ferrum::Browser whose page is the first window. - Driver#current_page is the window Capybara switched to, and Driver#window(page) holds its frame stack and dialog queue - The window handle methods move to Driver::Windows, the settings to Driver::Settings - url_blocklist=, url_allowlist=, their aliases and raise_on_unhandled_modal= move from driver.browser to driver - Driver#reset! restarts a browser that died, Browser#command did it before
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.
There's no public way to set up a page before anything happens on it. Code that wants to handle a popup's dialogs, or configure every page the same way, has to subclass
Pageand build pages through private API (Page.new,target.page=,maybe_sleep_if_new_window). Cuprite does exactly that today.browser.on_page { |page| }registers a block thatTarget#build_pagecalls with each page it builds, before returning it. It covers pages fromcreate_page, the default page, and pages another page opens. Pages already open aren't passed to it.Browser.newoption. Likeadd_extension, the browser delegates it to its options, which store the blocks. Each call adds a block, so a library and the user's own code can each register one.on_pagewithout a block raisesArgumentError.Targetalready holds the browser options.docs/3-navigation.md), RBS and the changelog are updated.create_pageis passed to the block before the call returns, a popup is passed too, and a call without a block raises.This is the first step of moving Cuprite off its
Ferrum::Pagesubclass. Cuprite will register its dialog handling, JS errors and viewport setup withon_pageright afterBrowser.new, before any page exists, and keep its own per-page state next to the page.