Web Scraping API
Run code in a browser session
Evaluate JavaScript in the session's page, optionally after navigating: success flag, the returned value, any thrown error, the page URL and the duration.
Endpoint
/v1/web/sessions/executelive · proven1 creditParameters
Query parameters
| Name | Required | Description | Example |
|---|---|---|---|
session_id | yes | Session id returned by web/sessions/create | ws_k3j2h1g0abcd |
code | yes | JavaScript evaluated in the page (a promise is awaited); the value is returned as JSON | document.title |
url | no | Navigate here first (optional) | https://example.com |
language | no | Only javascript: code runs in the page over DevTools, not node, python or bash on a host | javascript |
timeout | no | Milliseconds to allow, 1000 to 30000 (default 10000) | 10000 |
dry_run | no | Read a zero-credit estimate without fetching sources, running AI, or reserving credits. Cache status is a snapshot, not a guarantee at execution. | 1 |
Examples
Make the request
curl "https://www.monocrawl.com/v1/web/sessions/execute?session_id=ws_k3j2h1g0abcd&code=document.title&url=https%3A%2F%2Fexample.com" \ -H "x-api-key: mn_your_key_here"
TypeScript
const key = process.env.MONOCRAWL_API_KEY;
if (!key) throw new Error('Set MONOCRAWL_API_KEY on your server.');
const res = await fetch(
"https://www.monocrawl.com/v1/web/sessions/execute?session_id=ws_k3j2h1g0abcd&code=document.title&url=https%3A%2F%2Fexample.com",
{ headers: { "x-api-key": key } },
);
const body = await res.json();
if (!body.success) {
// one error shape for every endpoint — see /docs/errors
throw new Error(`${body.error.type}: ${body.error.message}`);
}
console.log(body.data, "credits left:", body.credits_remaining);Python
import os
import requests
res = requests.get(
"https://www.monocrawl.com/v1/web/sessions/execute?session_id=ws_k3j2h1g0abcd&code=document.title&url=https%3A%2F%2Fexample.com",
headers={"x-api-key": os.environ["MONOCRAWL_API_KEY"]},
timeout=60,
)
body = res.json()
if not body["success"]:
# one error shape for every endpoint — see /docs/errors
raise RuntimeError(f"{body['error']['type']}: {body['error']['message']}")
print(body["data"], "credits left:", body["credits_remaining"])Response
Response fields and example
This example is illustrative, not a captured live response. Variable-cost operations may settle a charge different from the list price below. A successful response puts the platform payload in data and reports the exact credits used, remaining balance, request id and cache status beside it.
{
"success": true,
"platform": "web",
"endpoint": "/v1/web/sessions/execute",
"data": {
"session_id": "ws_example",
"success": true,
"language": "javascript"
},
"credits_used": 1,
"credits_remaining": 99,
"request_id": "req_…",
"cached": false
}The example is illustrative and shows a documented subset of data. The fields below are optional across supported sources; nullable fields can also be absent. Preserve unknown values and accept additional fields.
Schema basis: reviewed response shaper. See schema coverage and validation limits.
Download the data JSON Schema. Validate response.data, not the whole envelope. A valid shape does not establish that every field or source record was returned.
| Field inside data | Type | Meaning |
|---|---|---|
session_id | string | null | session id |
result_type | string | null | result type |
error | string | null | error |
url | string | null | url |
language | string | null | language |
success | boolean | null | Whether page JavaScript completed. |
duration_ms | number | null | Execution duration. |
result is the JSON-serializable value of customer-supplied page JavaScript, so its type is intentionally unconstrained.
Failures use the typed error envelope. A confirmed uncharged or refunded failure reports zero; a pending reconciliation can report an unknown charge. Read credits_used and error.details.billing_status, and keep request_id for recovery. Response contract · Error reference