fix: browser.reset tries to dispose default implicit context #540#566
Merged
fix: browser.reset tries to dispose default implicit context #540#566
browser.reset tries to dispose default implicit context #540#566Conversation
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.
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.
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.
Old Chrome doesn't even show implicit context.
Target.getBrowserContextsreturns{"browserContextIds":[]}Target.setAutoAttachdoesn't send anyTarget.attachedToTargetevents nor doesTarget.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.attachedToTargetandTarget.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.