Tools/Browser

Execute JavaScript in the device's Chrome browser (CDP)

Changed on

Evaluates a JavaScript expression exactly once in the device's single, confirmed foreground Chrome tab via the Chrome DevTools Protocol and returns its JSON-serialized result. A responsive browser state without exactly one visible page returns DEVICE_NO_BROWSER_TARGET (400). Transient discovery, page-dial, or visibility-probe transport failures return CDP_TRANSPORT_UNAVAILABLE (503) with Retry-After and an executionOutcome; the service may start Chrome once and retry selection before Runtime.evaluate, but dial or probe recovery is skipped for a backgrounded Chrome, and a user script is never retried after its write or read. Devices without browser support return an unsupported-feature error.

post/devices/{deviceId}/browser/execute-script

Request

  • Base URL
    https://api.mobilerun.ai
  • URL
    https://api.mobilerun.ai/devices/{deviceId}/browser/execute-script
  • Auth
    HTTP bearer

Path parameters

deviceIdstring required

Headers

X-Device-Display-IDinteger

Request body

$schemastring uri

A URL to the JSON Schema for this object.

scriptstring 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 })().

Example request

{
  "$schema": "https://example.com/schemas/ExecuteScriptArgs.json"
}

Response

OK

$schemastring uri

A URL to the JSON Schema for this object.

resultunknown required

Example response

{
  "$schema": "https://example.com/schemas/ExecuteScriptOutputBody.json"
}

Changes