Appearance
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 chromiumScreenshots
Capture a screenshot of any URL:
sh
playwright screenshot https://example.com screenshot.pngFull-page screenshot:
sh
playwright screenshot --full-page https://example.com full.pngWait for a specific element before capturing:
sh
playwright screenshot --wait-for-selector ".loaded" https://example.com shot.pngWait a fixed duration (milliseconds):
sh
playwright screenshot --wait-for-timeout 3000 https://example.com shot.pngCustom viewport:
sh
playwright screenshot --viewport-size "1280, 720" https://example.com shot.pngEmulate a mobile device:
sh
playwright screenshot --device "Pixel 5" https://example.com mobile.pngApple 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.pngPDFs
Save a page as PDF (Chromium only):
sh
playwright pdf https://example.com page.pdfSpecify paper format:
sh
playwright pdf --paper-format A4 https://example.com page.pdfOpening pages interactively
Open a URL in a browser for manual inspection:
sh
playwright open https://example.comOpen in a specific browser:
sh
playwright open -b webkit https://example.comCode generation
Record interactions and generate test code:
sh
playwright codegen https://example.comOutput to a file:
sh
playwright codegen -o test.spec.js https://example.comGenerate Python instead of JavaScript:
sh
playwright codegen --target=python https://example.comCommon options
These options work across screenshot, pdf, open, and codegen:
| Option | Description |
|---|---|
-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-errors | Ignore certificate errors |
--timezone <zone> | Emulate timezone, e.g. "Europe/Rome" |
--lang <locale> | Emulate locale, e.g. "en-GB" |
--timeout <ms> | Timeout for actions |