Skip to content

ref(driver): drive a plain Ferrum browser and keep Capybara's windows in the driver - #399

Merged
route merged 4 commits into
mainfrom
page-hook
Nov 26, 2026
Merged

route merged 4 commits into
mainfrom
page-hook

Conversation

@route

@route route commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Builds against Ferrum main, which has on_page (rubycdp/ferrum#735) and no Target#page= (rubycdp/ferrum#736).

Cuprite::Page < Ferrum::Page and Cuprite::Browser < Ferrum::Browser are gone. driver.browser is a plain Ferrum::Browser, like Selenium's raw driver, and the driver keeps what Capybara needs on top:

  • The driver registers one on_page block that sets up every page Ferrum builds (default page, create_page, popups) before Ferrum hands it out: extension JS, viewport, device user agent, URL lists, JS errors.
  • Driver#current_page is the window Capybara switched to, Ferrum's browser.page until it switches. Driver#window(page) holds a page's frame stack and dialog queue (Driver::Window).
  • The window handle methods live in Driver::Windows, the settings in Driver::Settings.
  • Driver, Finder and Node run DOM and JavaScript calls in window.active_frame, and mouse, keyboard and navigation on current_page.
  • visit raises PendingConnectionsError through Ferrum's go_to! and NavigationTimeoutError#pendings.

Behavior changes:

  • Breaking: url_blocklist=, url_allowlist=, their aliases and raise_on_unhandled_modal= moved from page.driver.browser to page.driver.
  • page.driver.browser.* runs in the first window, also inside within_window. The switched-to window is page.driver.current_page.
  • A browser that died is restarted by reset!, between tests, instead of by the command that found it dead.
  • UnhandledModalError is raised around the Driver calls (visit, find, evaluate_script, execute_script, ...) and Node calls (command, the click), instead of around every page command.
  • The js_errors subscription starts after Ferrum's Runtime.enable instead of before it, so an exception in that short window on a page whose scripts were already running (a popup) isn't raised.

…ssing 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
… 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
@route route changed the title ref(browser): set pages up through Ferrum's on_page instead of subclassing Ferrum::Page ref(driver): drive a plain Ferrum browser and keep Capybara's windows in the driver Nov 26, 2026
@route
route marked this pull request as ready for review November 26, 2026 19:39
@route
route merged commit 8aa2ada into main Nov 26, 2026
6 checks passed
@route
route deleted the page-hook branch November 26, 2026 19:47
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.

1 participant