Skip to content

Playwright CLI

One-shot browser commands for screenshots, PDFs, and code generation — no script required.

Prerequisites

Install Playwright globally via Volta:

sh
volta install playwright
playwright install chromium

Screenshots

Capture a screenshot of any URL:

sh
playwright screenshot https://example.com screenshot.png

Full-page screenshot:

sh
playwright screenshot --full-page https://example.com full.png

Wait for a specific element before capturing:

sh
playwright screenshot --wait-for-selector ".loaded" https://example.com shot.png

Wait a fixed duration (milliseconds):

sh
playwright screenshot --wait-for-timeout 3000 https://example.com shot.png

Custom viewport:

sh
playwright screenshot --viewport-size "1280, 720" https://example.com shot.png

Emulate a mobile device:

sh
playwright screenshot --device "Pixel 5" https://example.com mobile.png

Apple devices (iPhone, iPad) require WebKit (playwright install webkit). Android devices work with the default Chromium install.

Dark mode:

sh
playwright screenshot --color-scheme dark https://example.com dark.png

PDFs

Save a page as PDF (Chromium only):

sh
playwright pdf https://example.com page.pdf

Specify paper format:

sh
playwright pdf --paper-format A4 https://example.com page.pdf

Opening pages interactively

Open a URL in a browser for manual inspection:

sh
playwright open https://example.com

Open in a specific browser:

sh
playwright open -b webkit https://example.com

Code generation

Record interactions and generate test code:

sh
playwright codegen https://example.com

Output to a file:

sh
playwright codegen -o test.spec.js https://example.com

Generate Python instead of JavaScript:

sh
playwright codegen --target=python https://example.com

Common options

These options work across screenshot, pdf, open, and codegen:

OptionDescription
-b, --browser <type>chromium (default), firefox, or webkit
--color-scheme <scheme>light or dark
--device <name>Emulate a device, e.g. "Pixel 5"
--viewport-size <size>Browser viewport, e.g. "1280, 720"
--ignore-https-errorsIgnore certificate errors
--timezone <zone>Emulate timezone, e.g. "Europe/Rome"
--lang <locale>Emulate locale, e.g. "en-GB"
--timeout <ms>Timeout for actions