Skip to main content
POST
JavaScript
The script is a single JavaScript expression, not a function body — skip the top-level return and wrap multi-statement logic in an IIFE:
The result must be JSON-serializable: undefined comes back as null, and NaN, Infinity, and -0 are returned as strings. Scripts run in Chrome itself — in-app WebViews are not reachable. iOS devices don’t support browser control and fail with 400. If CDP discovery, page connection, or the foreground visibility probe fails before Runtime.evaluate is sent, the service may start Chrome once and retry target selection. Dial and probe recovery only starts Chrome when it is already the foreground app (or the Chrome CDP socket itself is unavailable), so a backgrounded browser still fails closed. The response keeps the CDP_TRANSPORT_UNAVAILABLE 503 contract and reports the phase and recovery result in its details when recovery was attempted. A selection deadline shortfall, or failures while writing or reading Runtime.evaluate, is never replayed.
For a persistent session or full DevTools protocol access, connect a Playwright- or Puppeteer-style CDP client to the raw websocket at /devices/{deviceId}/browser/cdp instead of issuing one-shot calls.

Authorizations

Authorization
string
header
required

Bearer token via Authorization header

Headers

X-Device-Display-ID
integer<int64>
default:0
Required range: x >= 0

Path Parameters

deviceId
string
required

Body

application/json
script
string
required

JavaScript expression to evaluate in the device's foreground Chrome tab (CDP Runtime.evaluate). It is an expression, not a function body — the expression's value is returned (no top-level 'return'). Must evaluate to a JSON-serializable value; wrap multi-statement logic in an IIFE, e.g. (() => { ... ; return x })().

Response

OK

result
any
required

JSON-serialized return value of the script (null if it returned undefined). Non-JSON-serializable numbers (Infinity, NaN, -0) are returned as their string representation.

$schema
string<uri>
read-only

A URL to the JSON Schema for this object.

Example:

"https://example.com/schemas/ExecuteScriptOutputBody.json"