> ## Documentation Index
> Fetch the complete documentation index at: https://tbd-6fc993ce-mcp-browser-pool-docs-pr112.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Execute Playwright Code

> Run Playwright/TypeScript code against a browser session

Use `execute_playwright_code` to run Playwright/TypeScript automation code against a Kernel browser session. If you provide `session_id`, it uses that existing browser. If you omit `session_id`, it creates a browser and cleans it up after execution.

<Tip>Use `computer_action` with the `screenshot` action instead of `page.screenshot()` in your code. For a comprehensive page state snapshot, use `await page._snapshotForAI()`.</Tip>

## Parameters

| Parameter    | Description                                                                                       |
| ------------ | ------------------------------------------------------------------------------------------------- |
| `code`       | Playwright/TypeScript code with a `page` object in scope. Required.                               |
| `session_id` | Existing browser session ID. If omitted, a new browser is created and cleaned up after execution. |

## Example

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

Returns:

```json theme={null}
{
  "success": true,
  "result": "Example Domain",
  "replay_url": "https://..."
}
```
