> ## Documentation Index
> Fetch the complete documentation index at: https://kernel.sh/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# execute_playwright_code

> Run Playwright/TypeScript code against a browser session

Execute Playwright/TypeScript automation code against an existing Kernel browser session. This tool is a thin passthrough: it runs your code in the browser's VM and returns the result. It does not manage browser lifecycle — create and delete sessions with [`manage_browsers`](/docs/reference/mcp-server/tools/manage-browsers).

<Note>`session_id` is required. Unlike earlier versions, this tool no longer creates a browser when `session_id` is omitted, and no longer deletes the browser after execution. Create a session with `manage_browsers` (action `create`), pass its `session_id` here, then delete it with `manage_browsers` when done.</Note>

<Tip>Use `computer_action` with the `screenshot` action instead of `page.screenshot()` in your code. To read page state, return only what you need — prefer a targeted selector (e.g. `await page.locator('h1').innerText()`) or a region-scoped accessibility snapshot (e.g. `await page.locator('main').ariaSnapshot()`) rather than dumping the whole page.</Tip>

## Parameters

| Parameter    | Description                                                                                                                       |
| ------------ | --------------------------------------------------------------------------------------------------------------------------------- |
| `code`       | Playwright/TypeScript code with `page`, `context`, and `browser` objects in scope; the value you `return` is sent back. Required. |
| `session_id` | Existing browser session ID to run against. Required.                                                                             |

## Example

```json theme={null}
{
  "session_id": "session_abc123",
  "code": "await page.goto('https://example.com'); return await page.title();"
}
```

Returns:

```json theme={null}
{
  "success": true,
  "result": "Example Domain"
}
```

<Tip>To capture a video recording around your automation, start a recording with [`manage_replays`](/docs/reference/mcp-server/tools/manage-replays) before your calls and stop it when done.</Tip>
