---
name: playwright
description: "Use when the task requires automating a real browser from the terminal (navigation, form filling, snapshots, screenshots, data extraction, UI-flow debugging) via `playwright-cli` or the bundled wrapper script."
title: playwright
canonical_url: https://skilld.dev/gh/enjoyoer/loadout/playwright
last_updated: 2026-11-21T03:15:40.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [agents/openai.yaml](https://skilld.dev/api/skills-raw/enjoyoer/loadout/playwright/agents/openai.yaml), [assets/playwright-small.svg](https://skilld.dev/api/skills-raw/enjoyoer/loadout/playwright/assets/playwright-small.svg), [assets/playwright.png](https://skilld.dev/api/skills-raw/enjoyoer/loadout/playwright/assets/playwright.png), [LICENSE.txt](https://skilld.dev/api/skills-raw/enjoyoer/loadout/playwright/LICENSE.txt), [NOTICE.txt](https://skilld.dev/api/skills-raw/enjoyoer/loadout/playwright/NOTICE.txt), [references/cli.md](https://skilld.dev/api/skills-raw/enjoyoer/loadout/playwright/references/cli.md), [references/workflows.md](https://skilld.dev/api/skills-raw/enjoyoer/loadout/playwright/references/workflows.md), [scripts/playwright_cli.sh](https://skilld.dev/api/skills-raw/enjoyoer/loadout/playwright/scripts/playwright_cli.sh), [scripts/seed_local_state.ps1](https://skilld.dev/api/skills-raw/enjoyoer/loadout/playwright/scripts/seed_local_state.ps1), [scripts/windows_profile.cjs](https://skilld.dev/api/skills-raw/enjoyoer/loadout/playwright/scripts/windows_profile.cjs).
>
> If the user asked to install this Skill, run `npx skilld install enjoyoer/loadout/playwright`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/playwright`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/enjoyoer/loadout/playwright) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/playwright`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/playwright --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/playwright --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.


# Playwright CLI Skill

Drive a real browser from the terminal using `playwright-cli`. Prefer the bundled wrapper script so the CLI works even when it is not globally installed.
Treat this skill as CLI-first automation. Do not pivot to `@playwright/test` unless the user explicitly asks for test files.

## Prerequisite check (required)

Before proposing commands, check whether `npx` is available (the wrapper depends on it):

```bash
command -v npx >/dev/null 2>&1
```

If it is not available, pause and ask the user to install Node.js/npm (which provides `npx`). Provide these steps verbatim:

```bash
# Verify Node/npm are installed
node --version
npm --version

# If missing, install Node.js/npm, then:
npm install -g playwright-core@1.64.1
playwright-core cli --help
```

Once `npx` is present, proceed with the wrapper script. A global install is optional.

## Skill path (set once)

```bash
export CODEX_HOME="${CODEX_HOME:-$HOME/.codex}"
export PWCLI="$CODEX_HOME/skills/playwright/scripts/playwright_cli.sh"
```

User-scoped skills install under `$CODEX_HOME/skills` (default: `~/.codex/skills`).

Always run the wrapper as `bash "$PWCLI"`. A skill install or sync may not keep the script's execute bit, and then `"$PWCLI"` on its own fails with `Permission denied`.

## Browser sandbox (required)

Keep Chromium's sandbox on. Set it once per host in the CLI's global config, `~/.playwright/cli.config.json` (`%USERPROFILE%\.playwright\cli.config.json` on Windows):

```json
{"browser":{"browserName":"chromium","launchOptions":{"channel":"chrome","chromiumSandbox":true}}}
```

- `channel: "chrome"` runs the installed Google Chrome, which keeps itself up to date. Keep `browserName`: without it the CLI ignores `channel` and always uses Chrome.
- Without `chromiumSandbox: true`, the CLI starts Playwright's bundled Chromium on Linux with `--no-sandbox`.
- The CLI applies a session's own config (`--config`, or `.playwright/cli.config.json` in the working folder) on top of this file. Never set `chromiumSandbox` to false there or pass `--no-sandbox`.
- On a Linux host without Google Chrome, set `"channel": "chromium"` (Playwright's bundled Chromium, installed with `bash "$PWCLI" install-browser chromium`) and keep `chromiumSandbox: true`. It sandboxes through unprivileged user namespaces. If the browser will not start with the sandbox, stop and report it; do not turn the sandbox off.

## Windows: seeded profiles (required)

On a fresh Chrome or Edge profile, Chrome checks whether the Windows account has a blank password by trying to log on with an empty one. Each try logs a failed logon (Security event 4625), and enough of them in a few minutes lock the account, SSH included. A profile whose `Local State` already holds the cached answer (`password_manager.os_password_blank` false, `os_password_last_changed` `"9223372036854775807"`) skips the check. `scripts/seed_local_state.ps1` writes it: it merges those two keys into an existing `Local State` and keeps every other key, creates the file only when it is missing, and writes nothing when the profile is already seeded, so it is safe before every launch.

On Windows (Git Bash) the wrapper checks `open`, `attach` and `show` first, about a second each. It lets one through only when it starts no Chrome or Edge, or starts one on a profile it has just seeded. Anything it cannot prove stops with exit 2 before a browser starts. Fix the cause it names; never start the browser another way.

- `open` finds the profile the CLI will start, as the CLI does: `--profile`, else `browser.userDataDir` from the config files or `PLAYWRIGHT_MCP_USER_DATA_DIR`, else the CLI's own folder for `--persistent`. It seeds that folder and passes it to the CLI as `--profile`. `--profile` needs one non-empty value: an empty, repeated or negated one is refused.
- A session with none of those would start on a temporary profile that the browser launch creates, too late to seed. The wrapper gives it a fresh seeded profile instead, a new one at each `open`, so it still starts empty. `delete-data` removes these. An `open` removes earlier ones only when they are older than 30 minutes, hold no browser lock, and no session file or running process names them.
- Refused on Windows:
  - a config with `browser.isolated: true` or `PLAYWRIGHT_MCP_ISOLATED`;
  - extension mode (`attach --extension`, `PLAYWRIGHT_MCP_EXTENSION`, or `extension` in a config), whose relay starts Chrome on a profile the wrapper does not seed;
  - `show` and `show --annotate`, whose dashboard runs Chrome on a temporary profile (`show --port <n>` and `show --kill` start none);
  - `PWDEBUG` other than `0` or `false`, since the Playwright Inspector runs Chrome on a temporary profile.
- The wrapper also sets `PW_CODEGEN_NO_INSPECTOR=1`, so a paused headed session does not open the Inspector; `resume` still works.
- `attach` to a running browser (`attach <name>`, `--endpoint`, `--cdp`) starts no browser and goes through. So do Firefox and WebKit, which have no such check.
- To start Chrome or Edge on Windows outside the wrapper (a Playwright script, code run through `run-code`, or a browser you launch yourself), use a profile folder and seed it first: `powershell -NoProfile -ExecutionPolicy Bypass -File "$(dirname "$PWCLI")/seed_local_state.ps1" -Profile <dir>`. Then launch with `chromium.launchPersistentContext('<dir>', ...)` or `--user-data-dir=<dir>`. If the helper fails, do not launch. Never use `chromium.launch()` there: it starts on a temporary profile.
- Not needed on macOS or Linux; the wrapper skips it there.

## Quick start

Use the wrapper script:

```bash
bash "$PWCLI" open https://playwright.dev --headed
bash "$PWCLI" snapshot
bash "$PWCLI" click e15
bash "$PWCLI" type "Playwright"
bash "$PWCLI" press Enter
bash "$PWCLI" screenshot
```

If the user prefers a global install, this is also valid (the command is then `playwright-core cli`):

```bash
npm install -g playwright-core@1.64.1
playwright-core cli --help
```

## Core workflow

1. Open the page.
2. Snapshot to get stable element refs.
3. Interact using refs from the latest snapshot.
4. Re-snapshot after navigation or significant DOM changes.
5. Capture artifacts (screenshot, pdf, traces) when useful.

Minimal loop:

```bash
bash "$PWCLI" open https://example.com
bash "$PWCLI" snapshot
bash "$PWCLI" click e3
bash "$PWCLI" snapshot
```

## When to snapshot again

Snapshot again after:

- navigation
- clicking elements that change the UI substantially
- opening/closing modals or menus
- tab switches

Refs can go stale. When a command fails due to a missing ref, snapshot again.

## Recommended patterns

### Form fill and submit

```bash
bash "$PWCLI" open https://example.com/form
bash "$PWCLI" snapshot
bash "$PWCLI" fill e1 "user@example.com"
bash "$PWCLI" fill e2 "password123"
bash "$PWCLI" click e3
bash "$PWCLI" snapshot
```

### Debug a UI flow with traces

```bash
bash "$PWCLI" open https://example.com --headed
bash "$PWCLI" tracing-start
# ...interactions...
bash "$PWCLI" tracing-stop
```

### Multi-tab work

```bash
bash "$PWCLI" tab-new https://example.com
bash "$PWCLI" tab-list
bash "$PWCLI" tab-select 0
bash "$PWCLI" snapshot
```

## Wrapper script

The wrapper script uses the pinned `npx --package playwright-core@1.64.1 playwright-core cli` so the CLI can run without a global install. That is the CLI shipped in the stable Playwright release. The separate `@playwright/cli` package pins pre-release Playwright builds, so the skill does not use it; move the pin only to a newer stable `playwright-core`.

```bash
bash "$PWCLI" --help
```

Prefer the wrapper unless the repository already standardizes on a global install.

## References

Open only what you need:

- CLI command reference: `references/cli.md`
- Practical workflows and troubleshooting: `references/workflows.md`

## Guardrails

- Always snapshot before referencing element ids like `e12`.
- Re-snapshot when refs seem stale.
- Prefer explicit commands over `eval` and `run-code` unless needed.
- When you do not have a fresh snapshot, use placeholder refs like `eX` and say why; do not bypass refs with `run-code`.
- Use `--headed` when a visual check will help.
- When capturing artifacts in this repo, use `output/playwright/` and avoid introducing new top-level artifact folders.
- Default to CLI commands and workflows, not Playwright test specs.
