Skip to content

core(driver): add ExecutionContext.evaluateOnObject#17050

Merged
connorjclark merged 2 commits into
mainfrom
exec-context-evaluate-on-object
Jun 4, 2026
Merged

core(driver): add ExecutionContext.evaluateOnObject#17050
connorjclark merged 2 commits into
mainfrom
exec-context-evaluate-on-object

Conversation

@connorjclark

Copy link
Copy Markdown
Collaborator

This adds ExecutionContext.evaluateOnObject to wrap the CDP Runtime.callFunctionOn command, providing the same ergonomics, dependency serialization, and robust error handling as .evaluate().

Key benefits over raw session.sendCommand calls:

  • Protects native objects from page polyfills via _cachedNativesPreamble.
  • Properly throws on browser-side execution errors via exceptionDetails.
  • Safely manages this context binding and parameter serialization.

The WebMCP, WebMcpSchemaIssues, and TraceElements gatherers have been migrated to use this safer execution path. Unit tests and mock drivers are updated to reflect the new architecture.

If a page mocked the URL constructor, it was possible these old usages of Runtime.callFunctionOn would error. Now they won't.

ref #14003

@connorjclark connorjclark requested a review from a team as a code owner June 3, 2026 23:25
@connorjclark connorjclark requested review from paulirish and removed request for a team June 3, 2026 23:25
* @return {string}
*/
static serializeDeps(deps) {
deps = [pageFunctions.esbuildFunctionWrapperString, ...deps || []];

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was only here because direct callers of Runtime.callFunctionOn needed it to prevent minification errors from bundling / name mangling - but better to inject in _callFunctionOn. It also was already being done for _evaluateInContext (so it was sent twice for evaluate; now it's sent just once)

This adds `ExecutionContext.evaluateOnObject` to wrap the CDP
`Runtime.callFunctionOn` command, providing the same ergonomics,
dependency serialization, and robust error handling as `.evaluate()`.

Key benefits over raw `session.sendCommand` calls:
- Protects native objects from page polyfills via `_cachedNativesPreamble`.
- Properly throws on browser-side execution errors via `exceptionDetails`.
- Safely manages `this` context binding and parameter serialization.

The `WebMCP`, `WebMcpSchemaIssues`, and `TraceElements` gatherers
have been migrated to use this safer execution path. Unit tests
and mock drivers are updated to reflect the new architecture.
@connorjclark connorjclark merged commit 7174701 into main Jun 4, 2026
35 checks passed
@connorjclark connorjclark deleted the exec-context-evaluate-on-object branch June 4, 2026 18:44
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.

2 participants