Skip to content

fix: browser.reset tries to dispose default implicit context #540#566

Merged
route merged 1 commit intomainfrom
fix-540-reset
Feb 16, 2026
Merged

fix: browser.reset tries to dispose default implicit context #540#566
route merged 1 commit intomainfrom
fix-540-reset

Conversation

@route
Copy link
Copy Markdown
Member

@route route commented Feb 16, 2026

Old Chrome doesn't even show implicit context.
Target.getBrowserContexts returns {"browserContextIds":[]} Target.setAutoAttach doesn't send any Target.attachedToTarget events nor does Target.setDiscoverTargets. This context is not even registered in Ferrum.

More recent Chrome < 145 still returns empty {"browserContextIds":[]} but starts to show target and context in Target.attachedToTarget and Target.targetCreated.

Chrome >= 145 returns defaultBrowserContextId {"browserContextIds":[],"defaultBrowserContextId":"7354CC1034D553EE803954E18CDEB447"} and shows target and context as above.

--no-startup-window flag tells Chrome not to open any browser window on startup thus affecting implicit context in a more recent Chrome. When flag is passed we create our own default context, and thus can dispose it. When flag is not passed we use implicit context and thus cannot dispose it.

Old Chrome doesn't even show implicit context.
`Target.getBrowserContexts` returns `{"browserContextIds":[]}`
`Target.setAutoAttach` doesn't send any `Target.attachedToTarget` events nor does `Target.setDiscoverTargets`. This context is not even registered in Ferrum.

More recent Chrome < 145 still returns empty {"browserContextIds":[]} but starts to show target and context in `Target.attachedToTarget` and `Target.targetCreated`.

Chrome >= 145 returns defaultBrowserContextId `{"browserContextIds":[],"defaultBrowserContextId":"7354CC1034D553EE803954E18CDEB447"}` and shows target and context as above.

--no-startup-window flag tells Chrome not to open any browser window on startup thus affecting implicit context in a more recent Chrome. When flag is passed we create our own default context, and thus can dispose it. When flag is not passed we use implicit context and thus cannot dispose it.
@route route merged commit 56a46cd into main Feb 16, 2026
7 checks passed
@route route deleted the fix-540-reset branch February 16, 2026 12:20
crahles added a commit to fuchs-eule/ferrum that referenced this pull request Apr 20, 2026
…rror

Newer Chromium builds can report a "lost execution context" with the
phrase "Failed to find context with id <N>" instead of the historical
"Cannot find context with specified id". Match both so the error is
classified as a recoverable NoExecutionContextError (the client's retry
path) rather than bubbling up as a generic BrowserError.

This is the client.rb half of the previously ported rubycdp#545.
The contexts.rb half is dropped on rebase because upstream rubycdp#566
(56a46cd) addresses the underlying "dispose on missing context" issue
with a different, preferable approach (filter browser#reset against
Target.getBrowserContexts).
crahles added a commit to fuchs-eule/ferrum that referenced this pull request Apr 20, 2026
…ior (rubycdp#546)

Under Cuprite's default `flatten: true`, Chrome >= 145 exposes an
implicit default browser context whose id is reported via
`Target.attachedToTarget` but which `Browser.setDownloadBehavior`
refuses to scope to. The call raises

  Ferrum::BrowserError: Failed to find browser context for id <hex>

on the very first `Page#prepare_page`, breaking every system spec that
sets `save_path` (which Cuprite does automatically from
`Capybara.save_path`).

Rescue the specific error and retry without `browserContextId:` —
`Browser.setDownloadBehavior` accepts a browser-wide scope when the
key is omitted, which is equivalent to per-context scope under flatten.

Upstream issue: rubycdp#546
Related context on implicit default contexts: rubycdp#566
(56a46cd, "fix: `browser.reset` tries to dispose default implicit
context") documents the same Chrome >= 145 behavior class.
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