---
title: "Execute Playwright/TypeScript code against the browser"
method: POST
path: "/playwright/execute"
---

# Execute Playwright/TypeScript code against the browser

`POST /playwright/execute`

Execute arbitrary Playwright code in a fresh execution context against the browser running
on localhost:9222. The code has access to 'page', 'context', and 'browser' variables.
The result of the code execution is returned in the response.

'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. If active-tab resolution races with a target change, execution falls back
to an existing page. Use 'browser.contexts()' to select a context or page explicitly.

## 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. 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
- `500` — Internal Server Error

## Changes

> 52 revisions in range; 4 could not be searched.

- **2025-10-27** `073423d625a0` — 1 info
  - endpoint added
- **2025-06-27** `f980a92ab23f` — 1 breaking
  - api path removed without deprecation

[Change history](https://skmtc.dev/kernel/apis/kernel-images-api/changes/playwright/execute/post.md)

---

[API](https://skmtc.dev/kernel/apis/kernel-images-api.md) · [All operations](https://skmtc.dev/kernel/apis/kernel-images-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/kernel/kernel-images-api/revisions/7a641fa15a85/schema)
