evaluate_js
Executes arbitrary JavaScript expressions in the page or selected frame and returns the result, supporting promise awaiting and file output for large values.
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.
output_file: Write the string result to this path instead of returning
it. Use it for page blobs (bytecode, device state, rendered
documents): multi-kilobyte values otherwise truncate or flood the
conversation. The response carries path/bytes/sha256 and a short
preview.
output_encoding: "utf8" writes the string as UTF-8; "base64" decodes
the string first, for binary payloads.
overwrite: Allow replacing an existing output_file.
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; None when output_file is used) value_raw - raw string before cleaning (only when cleaning applied) type - "primitive" | "json" | "json_ascii" | "file" | "handle_fallback" | "error" output - (file only) {path, bytes, sha256, encoding} preview - (file only) bounded single-line preview of the string result 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
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"expression": "<expression>"
},
"name": "evaluate_js"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| world | No | isolated | |
| frame_url | No | ||
| overwrite | No | ||
| expression | Yes | ||
| frame_name | No | ||
| frame_index | No | ||
| output_file | No | ||
| await_promise | No | ||
| result_format | No | auto | |
| output_encoding | No | utf8 |