evaluate_js
Evaluates a JavaScript expression in the page’s global scope using DevTools console semantics, returning serialized values or previews for non-serializable objects.
Instructions
Evaluate a JavaScript expression in the page, in global scope, with the same semantics as the DevTools console. Returns the real value when it serialises; objects that cannot (DOM nodes, Errors, Maps, class instances) come back as a preview instead: class name plus a first level of properties, marked … where Chrome truncated it — readable, not parseable as the value. Top-level await works, but an expression that merely RETURNS a promise is NOT awaited — it comes back as a pending Promise, exactly as in the console. The call returns as soon as your expression finishes its synchronous work, before queued microtasks run, so the state triggered by a click is not visible in the same call: put await Promise.resolve() between the click and the read, or read in a second call. At a breakpoint this still evaluates globally and cannot see local or closure variables — use evaluate_at_frame for those. For the element selected in the Elements panel ($0), use get_inspected_element.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expression | Yes | JS source evaluated as-is. A function is not called — wrap it: `(() => { ... })()` |