Execute Playwright code in a session using theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/remorses/playwriter/llms.txt
Use this file to discover all available pages before exploring further.
-e flag:
Required flags
Session ID (get one with
playwriter session new). The session’s state object persists across commands.JavaScript code to execute in the browser context
Optional flags
Execution timeout in milliseconds
Remote relay server host (overrides PLAYWRITER_HOST)
Authentication token (overrides PLAYWRITER_TOKEN)
Basic examples
Navigate to a page
Click a button
Get page title
Take a screenshot
Get accessibility snapshot
Quoting rules
Always use single quotes for-e to prevent bash from interpreting special characters:
Multiline code
Heredoc (recommended)
Best for multiline code with complex quoting:'EOF' delimiter disables all bash expansion. Any character works inside, including $, backticks, and single quotes.
$’…’ syntax
Alternative for multiline, but beware of escape sequences:Quoting summary
| Syntax | Bash expansion | Use case |
|---|---|---|
'...' | None | One-liners (best for simple code) |
<<'EOF' | None | Multiline code (best for complex code) |
$'...' | \n, \t, \' only | Multiline when you need escape sequences |
"..." | Full | ❌ Never use for JavaScript code |
Timeout option
Default timeout is 10 seconds. Increase for long-running operations:Available variables
All execute calls have access to:Object persisted between calls within your session. Each session has its own isolated state. Use to store pages, data, listeners.
A default page (may be shared with other agents). Prefer creating your own page and storing it in
state.Browser context. Access all pages via
context.pages().Load Node.js modules (e.g.,
const fs = require('node:fs')). ESM import is not available.setTimeout, setInterval, fetch, URL, Buffer, crypto, etc.
Output and errors
The command prints the result to stdout:Advanced examples
Store network requests
Load file content
Extract data with page.evaluate
Work with iframes
Environment variables
Default session ID (can be overridden with
-s)Default relay server host (can be overridden with
--host)Authentication token for remote relay servers (can be overridden with
--token)Troubleshooting
“Error: -s/—session is required” Create a session first:-s.
“Warning: Extension not connected”
Click the Playwriter extension icon on any tab. The icon turns green when connected.
Timeout errors
Increase the timeout: