Repository navigation
Conversation
This was referenced Oct 19, 2026
…keeping the old one with warnings
`#evaluate`, `#evaluate_async`, `#execute`, `#evaluate_func` and `#evaluate_on` had four argument conventions and three
return semantics between them, and scripts reached their arguments through `arguments[0]`. This adds one convention for
all of them, without changing what any existing call returns.
New: keyword arguments become the script's parameters, `page.evaluate("a + b", a: 1, b: 2)`, bound by name when the
script is a function declaration. A script may be a function or arrow declaration, used as-is, and may `await`; promises
it returns are awaited, bounded by `timeout:` and raising `ScriptTimeoutError`, now a `TimeoutError`. Added
`#evaluate_handle`, returning a `Ferrum::RemoteObject`, and `Node#execute`/`Node#evaluate_handle`. Scripts are read by a
small scanner, `Frame::Script`, that skips strings, template literals, regular expressions and comments.
Compatible: a call that doesn't use any of that runs exactly as before, through `Runtime::Legacy`, which also keeps
`#evaluate_async`, `#evaluate_func` and `#evaluate_on`. Positional arguments keep working. What 0.21 will do differently
is detected and warned about with a rewrite, pointing at the first caller outside installed gems: keywords read through
`arguments`, mixed positional and keyword arguments, scripts of several statements or that never run, promises and
thenables that will be awaited, thrown non-Errors that will raise, and nodes `Node#evaluate` will resolve.
`FERRUM_DEPRECATION_WARNINGS=raise` turns the warnings into errors, `0` silences them.
route
force-pushed
the
feat/js-api-compat
branch
from
October 21, 2026 19:20
438925a to
087049a
Compare
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.
First of two steps that redesign the JavaScript evaluation API. This one ships in 0.20 and changes no existing result; the next one, for 0.21, removes the old API.
New API
Frame::Script) that skips strings, template literals, regular expressions and comments.Promise.racein the page, so pages that replacePromiseor mock timers don't break it.ScriptTimeoutErroris now aTimeoutError, sorescue Ferrum::TimeoutErrorkeeps catching it.Compatibility
A call takes the new path only if it uses something only the new API has: named arguments, a function declaration,
await,timeout:, or a new method. Anything else runs the code frommainunchanged, inFrame::Runtime::Legacy. That includesevaluate_async,evaluate_funcandevaluate_on. Positional arguments keep working, now and after 0.21.For old-style calls, Ferrum detects what 0.21 will do differently and warns with a suggested rewrite (the full table is in
docs/13-javascript.md, "Upgrading to 0.21"):arguments, or mixed with positional arguments"a(); b"Runtime.compileScriptof the 0.21 wrapper, cached per scriptthencheck on object resultsErrorwill raiseexceptionDetailswith a non-error resultNode#evaluatewill resolve nodes and datesWarnings point at the first caller outside installed gems, which for Capybara users is the line calling
execute_script. They print once per call site.FERRUM_DEPRECATION_WARNINGS=raiseturns them into errors, and0silences them.Verified
A script comparing about 40 old-style calls against
mainreturns identical results. The one exception isevaluate("new Error('x')"), which used to crash withNoMethodErrorand now raisesJavaScriptError.spec/frame/runtime/legacy_spec.rbpins those results and warnings.