Skip to main content
POST
/
browsers
/
{id}
/
playwright
/
execute
JavaScript
import Kernel from '@onkernel/sdk';

const client = new Kernel({
  apiKey: 'My API Key',
});

const response = await client.browsers.playwright.execute('id', { code: 'code' });

console.log(response.success);
{
  "success": true,
  "result": "<any>",
  "error": "<string>",
  "stdout": "<string>",
  "stderr": "<string>"
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Path Parameters

id
string
required

Browser session ID

Body

application/json

Request to execute Playwright code

code
string
required

TypeScript/JavaScript code to execute. The code has access to 'page', 'context', and 'browser' variables. It runs within a function, so you can use a return statement at the end to return a value. This value is returned as the result property in the response. Example: "await page.goto('https://example.com'); return await page.title();"

timeout_sec
integer
default:60

Maximum execution time in seconds. Default is 60.

Required range: 1 <= x <= 300

Response

Code executed successfully

Result of Playwright code execution

success
boolean
required

Whether the code executed successfully

result
any

The value returned by the code (if any)

error
string

Error message if execution failed

stdout
string

Standard output from the execution

stderr
string

Standard error from the execution