evaluate_js
Execute JavaScript in a page context to inspect or manipulate web pages, returning results with configurable frame targeting and output formatting.
Instructions
Execute an arbitrary JavaScript expression in the page context and return the result.
v1.0.1 fix: correctly handles undefined/null/void/Symbol return values without triggering JSON.parse crashes.
Default auto mode preserves legacy cleaning and smart JSON parsing; it may strip BOM/whitespace and replace lone surrogates. value_raw is not a code-unit-preserving transport. json_ascii returns explicit JSON text before transport/cleaning, preserving JSON string code units. Evaluation is never replayed after a failure.
Args:
expression: JavaScript expression. Must be a single expression, not
top-level var/let/const/function declarations (Playwright limitation).
Wrap in IIFE if needed: (() => { var x = 1; return x; })()
await_promise: If True, awaits Promise results (default True).
world: "isolated" preserves the existing Playwright execution context.
"main" prefers Camoufox's native mw: channel so page globals
created by site scripts are visible, with an explicit Firefox
window.wrappedJSObject.eval fallback for older/attached servers.
frame_url: Optional exact frame URL or shell-style wildcard.
frame_name: Optional exact frame name or shell-style wildcard.
frame_index: Optional zero-based index from get_page_info().frames.
result_format: "auto" (legacy cleanup) or "json_ascii" (ASCII JSON text
in value, not parsed/trimmed). json_ascii follows JSON.stringify:
tag non-finite numbers/-0/undefined explicitly if their distinction
matters; it is not a lossless arbitrary-object graph serializer.
Returns: dict with keys: value - cleaned value (parsed JSON if applicable) value_raw - raw string before cleaning (only when cleaning applied) type - "primitive" | "json" | "handle_fallback" | "error" world - selected execution world frame - selected frame's current snapshot metadata execution_backend - isolated, Camoufox native, or wrappedJSObject warnings - list of applied cleanups, if any hint - (error only) friendly fix suggestion or None
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| world | No | isolated | |
| frame_url | No | ||
| expression | Yes | ||
| frame_name | No | ||
| frame_index | No | ||
| await_promise | No | ||
| result_format | No | auto |