Repository navigation
fix(runtime)!: evaluate in one call, raise dedicated errors for a navigation and a foreign object - #755
Merged
Conversation
…igation and a foreign object An object result of evaluate took a second Runtime.callFunctionOn to await a possible thenable, so its contents crossed the socket twice, and every awaited script took two calls. The first call now sends awaitPromise: true, which awaits native promises and thenables alike. A script that starts a navigation and returns an object no longer raises NoExecutionContextError, the second call used to lose that race. A single call needs the retry to be safe, so errors are mapped by what they mean: - "Inspected target navigated or closed" and "Execution context was destroyed." raise ExecutionContextDestroyedError instead of NodeNotFoundError or a plain BrowserError. No node is involved, and a command cut off this way may have already run, so it isn't retried. Node#exists? still returns false for it. - "Argument should belong to the same JavaScript world as target object" raises ForeignObjectError instead of NodeNotFoundError: a Node or RemoteObject argument from a previous page or another isolated world, which can't succeed on a retry. NodeNotFoundError and NoExecutionContextError, the errors evaluate still retries, are now raised only before the script runs.
route
added a commit
to rubycdp/cuprite
that referenced
this pull request
Nov 30, 2026
…bjectError as a stale node (#403) Ferrum raises ExecutionContextDestroyedError for a command cut off by a navigation and ForeignObjectError for a node argument from another page or world, both were NodeNotFoundError before (rubycdp/ferrum#755). Node commands raise ObsoleteNode for them, Capybara finds the element again after either, and set doesn't fail when a navigation cuts off its refocus.
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.
An object result of
evaluatewithout a subtype (a plain object, a class instance, a built-in likeMath) took twoRuntime.callFunctionOncalls, both with deep serialization, so its contents crossed the socket twice. The second call awaited a possible thenable, since Chrome marks only native promises. Everyawaittook two calls as well.Now the first call sends
awaitPromise: true, which awaits native promises and any thenable in the same call, as Puppeteer and Playwright do:The second call used to lose the race with a navigation the script started, that's the last line.
The await was a separate call so that it stayed out of the retries: an await cut off by a navigation raised
NodeNotFoundError, which is retried, and would run the script again. So errors are now mapped by what they mean:ExecutionContextDestroyedError. No node is involved, and a command cut off this way may have already run, so it isn't retried.ForeignObjectError: aNodeorRemoteObjectargument from a previous page or another isolated world. A retry can't help it.The errors
evaluatestill retries,NodeNotFoundErrorandNoExecutionContextError, are now raised only before the script runs: a stale context id or aNodeargument that can't be resolved yet.Breaking:
ExecutionContextDestroyedErrorinstead ofNodeNotFoundError, or a plainBrowserErrorin an iframe.ForeignObjectErrorinstead ofNodeNotFoundError.