evaluate_js
Execute a JavaScript expression in the page context and receive a cleaned, serializable result. Automatically handles promises, special values, and serialization errors with fallback and warnings.
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.
Return value is aggressively cleaned (strips BOM, fixes lone surrogates, trims whitespace, auto-parses JSON strings). If direct evaluate fails with serialization error, automatically falls back to evaluate_handle.
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).
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" warnings - list of applied cleanups, if any hint - (error only) friendly fix suggestion or None
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expression | Yes | ||
| await_promise | No |