Browser Playwright

Execute Playwright/TypeScript code against the browser

Changed on

Execute arbitrary Playwright code in a fresh execution context against the browser. The code runs in the same VM as the browser, minimizing latency and maximizing throughput. It has access to 'page', 'context', 'browser', and 'webmcp' variables. Use 'webmcp.listTools()' to discover browser-wide WebMCP tools and 'webmcp.invokeTool(toolRef, input?, { timeoutSec? })' to invoke an exact registration. It can return a value, and this value is returned in the response.

Every call runs in an executor: a dedicated Node.js process with its own browser connection. Calls on different executors run concurrently; calls on the same executor run one at a time. A timeout, crash, or blocked event loop in one executor does not affect other executors. After a timeout the executor keeps its process and drops its browser connection, so code abandoned by the timeout cannot keep driving the browser. After a crash or a blocked event loop, the next call on that executor starts a fresh process.

Calls without 'executor' run in the executor named 'default', which always exists and is the same as passing 'executor: "default"'. In the default executor, 'page' is bound to an active tab reported by Chrome. In single-window sessions, this is the foreground tab. When multiple browser windows are open, Chrome reports one active tab per window and the selected window is unspecified. 'context' is the BrowserContext that owns the selected page. Use 'browser.contexts()' to select a context or page explicitly.

Pass any other name to run the call in a named executor. The first call with a new name creates it. Each named executor owns a tab: its first call opens a new background tab in the default browser context, and 'page' is bound to that tab on every later call while it stays open. Opening it does not change the active tab of an existing window. If the tab is closed, the next call opens a new one and reports 'tab.created: true'. Executor code can still reach other tabs through 'context' and 'browser'; ownership only decides what 'page' is bound to. Use named executors to drive several tabs of one browser in parallel.

A browser can have at most 8 named executors; the default executor does not count. A call that would create another returns 409 with the current executors; delete one with DELETE /browsers/{id_or_name}/playwright/executors/{name}. Named executors are not removed automatically while the browser runs; when it shuts down, they are removed and their tabs closed.

post/browsers/{id_or_name}/playwright/execute

Request

  • Base URL
    https://api.onkernel.com
  • URL
    https://api.onkernel.com/browsers/{id_or_name}/playwright/execute
  • Auth
    HTTP bearer

Path parameters

id_or_namestring required

Browser session ID or name

Headers

Idempotency-Keystring

Makes retrying the call safe. A call with a key already used on this browser returns the first call's response instead of running the code again, waiting for it if it is still running. A call with a key keeps running for 10 seconds after its last caller disconnects, so a retry can collect its response; after that it is cancelled like a call without a key. A response is kept for 10 minutes once the call finishes, and only the most recent responses are kept. A call rejected before the code runs, such as with 400, 409 or 429, does not use up its key. The Kernel SDKs send a key automatically and reuse it when they retry.

Request body

codestring 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();"

executorstring

Name of a Playwright executor. Calls with the same name run in the same executor, one at a time; the first call with a new name creates it. Calls on different executors run concurrently. 'default' names the executor that runs calls without a name.

timeout_secinteger

Maximum execution time in seconds. Default is 60.

Example request

{
  "executor": "checkout"
}

Response

Code executed successfully

errorstring

Error message if execution failed

resultunknown
stderrstring

Standard error from the execution

stdoutstring

Standard output from the execution

successboolean required

Whether the code executed successfully

Changes

    • info

      added the new optional header request parameter Idempotency-Key

    • info

      added the non-success response with the status

    • info

      added the new optional request property

    • info

      added the non-success response with the status

    • info

      added the optional property to the response with the status