Repository navigation
Conversation
This was referenced Oct 19, 2026
route
force-pushed
the
feat/js-api-compat
branch
5 times, most recently
from
October 22, 2026 16:58
73bae46 to
b69b229
Compare
…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 by default.
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: by default, 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 the new way does 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. Detection reads the result and its properties without running code on it.
`FERRUM_DEPRECATION_WARNINGS=raise` turns the warnings into errors, `0` silences them.
`FERRUM_JS_API=new` runs every call the new way. 0.21 makes it the default, keeping `FERRUM_JS_API=legacy` to switch
back, and 0.22 removes `Runtime::Legacy` and the deprecated methods.
route
force-pushed
the
feat/js-api-compat
branch
from
October 22, 2026 18:37
b69b229 to
a57fff3
Compare
Member
Author
|
Replaced by #673, a fresh PR with the same code and a migration guide in the description. |
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.
Redesigns the JavaScript evaluation API so it can land at once without breaking anyone's scripts.
FERRUM_JS_APIpicks how old-style scripts run:FERRUM_JS_API=newto try the new wayFERRUM_JS_API=legacyto go back while migratingevaluate_async,evaluate_func,evaluate_onThe old code lives untouched (apart from warnings) in
Frame::Runtime::Legacy, and the new pipeline is separate, so 0.21 is a one-line default flip and 0.22 deleteslegacy.rbandutils/deprecate.rb. The switch is an environment variable rather than a browser option, so it's clearly temporary and removing it breaks no code.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.Legacy mode
A call takes the new path, even in legacy mode, if it uses something only the new API has: named arguments, a function declaration,
await,timeout:, or a new method. So Ferrum's own calls and libraries that use these forms behave the same in both modes. Anything else runs the code frommainunchanged.For those old-style calls, Ferrum detects what the new way does 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.compileScript(parses, doesn't run), cached per scriptRuntime.getPropertiesfor athenfunctionErrorwill raiseexceptionDetailswith a non-error resultNode#evaluatewill resolve nodes and datesRuntime.getPropertiesfor arraysThe script runs once, and detection never runs code on its result, so getters and proxy traps don't fire. Warnings point at the first caller outside installed gems, which for Capybara users is the line calling
execute_script, and 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 in legacy mode. The one exception isevaluate("new Error('x')"), which used to crash withNoMethodErrorand now raisesJavaScriptError.spec/frame/runtime/legacy_spec.rbpins those results and warnings, andspec/frame/runtime_spec.rbcoversFERRUM_JS_API=new. The suite passes in both modes.Replaces #660 and #661.