---
title: "Execute Playwright/TypeScript code against the browser"
method: POST
path: "/browsers/{id}/playwright/execute"
tags: ["Browser Playwright"]
---

# Execute Playwright/TypeScript code against the browser

`POST /browsers/{id}/playwright/execute`

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', and 'browser' variables.
It can `return` a value, and this value is returned in the response.

## Path parameters

- `id` string, required

## Request body

- ExecutePlaywrightRequest — 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 — Maximum execution time in seconds. Default is 60.

## Response `200`

Code executed successfully

- ExecutePlaywrightResult — Result of Playwright code execution
  - `success` boolean, required — Whether the code executed successfully
  - `result` unknown
  - `error` string — Error message if execution failed
  - `stdout` string — Standard output from the execution
  - `stderr` string — Standard error from the execution

## Other responses

- `400` — Bad Request – invalid input
- `500` — Internal Server Error

---

[API](https://skmtc.net/kernel/apis/kernel-api.md) · [All operations](https://skmtc.net/kernel/apis/kernel-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/kernel/kernel-api/revisions/9e8ce9fcf5e1/schema)
