POST /v1/browser/{session_id}/execute runs code or a prompt in a session you opened, and answers with what it printed and returned. Run as many calls as you need on one session, then close it.
Run code
Open a session first. In your code,page is the session’s page, with Playwright-style methods. Every page call is asynchronous, so await it. This call opens a page, then returns its title and address.
result is the value your code returned, as text. output is what it printed.
200, so check exitCode and error before you trust result.
Choose a language
Sendlanguage as node (the default), python or bash. Each reads the same page.
This Python run returned
exitCode 0 and the same result as the Node run above.
Run a prompt
Sendprompt instead of code to say what you want in plain words. Stophy clicks and types on the page for you, up to 50 steps, and answers in words.
result and output hold the answer. steps lists what was done, and page is where the session ended up. When the prompt could not be finished, exitCode is 1 and stderr says why.
Options
Sendcode or prompt. A body with neither returns 400 invalidRequest with Send code or a prompt.
Read the response
Price
A call costs nothing. What changes is the session’s price: a session is $0.06 per hour open, and once a prompt has run it is $0.84 per hour for its whole time. Code never raises the price. Traffic is billed as usual, per GB. A session that opened, ran one prompt and closed after 27 seconds cost $0.022: one minute of browser time at the prompt price, $0.014, and $0.008 for 1.3 MB of traffic. See Browser sessions.Limits and errors
- The first call right after a session opens can fail with
503 internalErrorand the messageWe couldn't complete your request. Try again shortly.It is retryable: send it again. - Code that runs past
timeoutreturnskilled: trueanderrorThe code ran out of time. - A session that has ended returns
410 notFoundwithThis browser session has ended. urlandzeroDataRetentionare not accepted on this call. Open the page withpage.gotoin your code, and set zero data retention when you open the session.
Related
- Browser sessions opens and closes the session this call runs in.
- Files puts a file in the session for a file field to use.
- Tasks runs a goal on a public site without a session of your own.
- Browser actions run steps on a page during one scrape.