patchright-cli 0.4.1__tar.gz → 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. patchright_cli-0.5.0/.claude-plugin/marketplace.json +20 -0
  2. patchright_cli-0.5.0/.github/workflows/ci.yml +34 -0
  3. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/CLAUDE.md +14 -3
  4. patchright_cli-0.5.0/Makefile +18 -0
  5. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/PKG-INFO +35 -3
  6. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/README.md +30 -2
  7. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/pyproject.toml +11 -1
  8. patchright_cli-0.5.0/skills/patchright-cli/SKILL.md +348 -0
  9. patchright_cli-0.5.0/skills/patchright-cli/references/request-mocking.md +103 -0
  10. patchright_cli-0.5.0/skills/patchright-cli/references/running-code.md +129 -0
  11. patchright_cli-0.5.0/skills/patchright-cli/references/session-management.md +106 -0
  12. patchright_cli-0.5.0/skills/patchright-cli/references/snapshot-refs.md +86 -0
  13. patchright_cli-0.5.0/skills/patchright-cli/references/storage-state.md +113 -0
  14. patchright_cli-0.5.0/skills/patchright-cli/references/tracing.md +53 -0
  15. patchright_cli-0.5.0/skills/patchright-cli/references/video-recording.md +85 -0
  16. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/src/patchright_cli/__init__.py +1 -1
  17. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/src/patchright_cli/cli.py +109 -2
  18. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/src/patchright_cli/daemon.py +7 -2
  19. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/src/patchright_cli/ref_registry.py +27 -1
  20. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/src/patchright_cli/snapshot.py +4 -2
  21. patchright_cli-0.5.0/tests/test_cli_config.py +203 -0
  22. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/tests/test_ref_registry.py +51 -0
  23. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/uv.lock +111 -1
  24. patchright_cli-0.4.1/.claude-plugin/marketplace.json +0 -21
  25. patchright_cli-0.4.1/skills/patchright-cli/SKILL.md +0 -562
  26. patchright_cli-0.4.1/tests/test_cli_config.py +0 -74
  27. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/.claude-plugin/skills/browser-automation.json +0 -0
  28. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/.github/workflows/publish.yml +0 -0
  29. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/.gitignore +0 -0
  30. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/.pre-commit-config.yaml +0 -0
  31. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/CONTRIBUTING.md +0 -0
  32. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/LICENSE +0 -0
  33. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/docs/installation.md +0 -0
  34. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/docs/superpowers/plans/2026-04-14-cdp-attach.md +0 -0
  35. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/docs/superpowers/plans/2026-04-14-cli-enhancements.md +0 -0
  36. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/docs/superpowers/plans/2026-04-14-codegen.md +0 -0
  37. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/docs/superpowers/plans/2026-04-14-context-config-and-permissions.md +0 -0
  38. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/docs/superpowers/plans/2026-04-14-show-dashboard.md +0 -0
  39. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/patchright-cli +0 -0
  40. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/patchright-cli.cmd +0 -0
  41. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/src/patchright_cli/__main__.py +0 -0
  42. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/src/patchright_cli/dashboard.py +0 -0
  43. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/tests/__init__.py +0 -0
  44. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/tests/fixture.html +0 -0
  45. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/tests/test_daemon_handlers.py +0 -0
  46. {patchright_cli-0.4.1 → patchright_cli-0.5.0}/tests/test_e2e.py +0 -0
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "patchright-cli",
3
+ "owner": {
4
+ "name": "Han Zhu"
5
+ },
6
+ "metadata": {
7
+ "description": "Anti-detect browser automation CLI & Skills for AI agents, powered by Patchright",
8
+ "version": "0.5.0"
9
+ },
10
+ "plugins": [
11
+ {
12
+ "name": "patchright-cli",
13
+ "description": "Anti-detect browser automation skill using Patchright (undetected Playwright fork)",
14
+ "source": "./",
15
+ "skills": [
16
+ "./skills/patchright-cli"
17
+ ]
18
+ }
19
+ ]
20
+ }
@@ -0,0 +1,34 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ lint:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ - uses: astral-sh/setup-uv@v6
15
+ with:
16
+ version: ">=0.7,<0.8"
17
+ python-version: "3.12"
18
+ - run: uv venv && uv pip install -e ".[dev]"
19
+ - run: uv run pre-commit run --all-files
20
+
21
+ test:
22
+ strategy:
23
+ matrix:
24
+ os: [ubuntu-latest, windows-latest]
25
+ python-version: ["3.10", "3.12"]
26
+ runs-on: ${{ matrix.os }}
27
+ steps:
28
+ - uses: actions/checkout@v4
29
+ - uses: astral-sh/setup-uv@v6
30
+ with:
31
+ version: ">=0.7,<0.8"
32
+ python-version: ${{ matrix.python-version }}
33
+ - run: uv venv && uv pip install -e ".[dev]"
34
+ - run: uv run pytest tests/ -v --ignore=tests/test_e2e.py
@@ -26,7 +26,18 @@ python -m patchright_cli <command> [args...]
26
26
  patchright-cli <command> [args...]
27
27
  ```
28
28
 
29
- There are no automated tests yet — changes are tested manually via the CLI.
29
+ ## Testing
30
+
31
+ ```bash
32
+ # Unit tests (no browser required)
33
+ pytest tests/ -v --ignore=tests/test_e2e.py
34
+
35
+ # E2E tests (requires Chrome)
36
+ pytest tests/test_e2e.py -v
37
+
38
+ # Lint
39
+ pre-commit run --all-files
40
+ ```
30
41
 
31
42
  ## Architecture
32
43
 
@@ -38,9 +49,9 @@ CLI (cli.py) --TCP:9321--> Daemon (daemon.py) --Patchright--> Chrome
38
49
 
39
50
  - **CLI (`src/patchright_cli/cli.py`)**: Stateless thin client. Parses argv manually (not click subcommands), builds a JSON `{command, args, options, cwd}` message, sends it over a length-prefixed TCP socket to the daemon, prints the response, and exits. All commands are defined in the `COMMANDS_HELP` dict and `ALL_COMMANDS` list.
40
51
 
41
- - **Daemon (`src/patchright_cli/daemon.py`)**: Long-running async process managing browser sessions. Auto-spawned on `open` via `ensure_daemon_running()` which launches a subprocess. Uses `DaemonState` → multiple `Session` objects, each owning a Patchright persistent browser context. Command dispatch is a large `handle_command()` function with if/elif branches. Console capture uses CDP sessions (not Playwright's `page.on('console')`) because Patchright suppresses it.
52
+ - **Daemon (`src/patchright_cli/daemon.py`)**: Long-running async process managing browser sessions. Auto-spawned on `open` via `ensure_daemon_running()` which launches a subprocess. Uses `DaemonState` → multiple `Session` objects, each owning a Patchright persistent browser context. Command dispatch uses `@register()` decorated handlers in `COMMAND_HANDLERS` dict, dispatched by `handle_command()`. Console capture uses CDP sessions (not Playwright's `page.on('console')`) because Patchright suppresses it.
42
53
 
43
- - **Snapshot (`src/patchright_cli/snapshot.py`)**: Two-pass DOM scanner injected as JavaScript: Pass 1 uses TreeWalker to assign `data-patchright-ref` attributes (`e1`, `e2`, ...) in document order; Pass 2 builds a nested tree. Python side converts to flat YAML. Snapshots are saved to `.patchright-cli/` in the caller's cwd.
54
+ - **Snapshot (`src/patchright_cli/snapshot.py`)**: Uses Playwright's native `aria_snapshot()` to get the accessibility tree. `RefRegistry` annotates each node with sequential refs (`e1`, `e2`, ...). Snapshots are saved as YAML to `.patchright-cli/` in the caller's cwd.
44
55
 
45
56
  ## Key Design Decisions
46
57
 
@@ -0,0 +1,18 @@
1
+ .PHONY: install-dev lint test-unit test-e2e test build
2
+
3
+ install-dev:
4
+ uv venv && uv pip install -e ".[dev]" && pre-commit install
5
+
6
+ lint:
7
+ pre-commit run --all-files
8
+
9
+ test-unit:
10
+ pytest tests/ -v --ignore=tests/test_e2e.py
11
+
12
+ test-e2e:
13
+ pytest tests/test_e2e.py -v
14
+
15
+ test: lint test-unit
16
+
17
+ build:
18
+ uv build
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: patchright-cli
3
- Version: 0.4.1
3
+ Version: 0.5.0
4
4
  Summary: Anti-detect browser automation CLI using Patchright (undetected Playwright fork)
5
5
  Project-URL: Homepage, https://github.com/AhaiMk01/patchright-cli
6
6
  Project-URL: Repository, https://github.com/AhaiMk01/patchright-cli
@@ -25,6 +25,10 @@ Requires-Dist: aiohttp>=3.9
25
25
  Requires-Dist: click
26
26
  Requires-Dist: patchright
27
27
  Requires-Dist: pyyaml
28
+ Provides-Extra: dev
29
+ Requires-Dist: pre-commit; extra == 'dev'
30
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
31
+ Requires-Dist: pytest>=8.0; extra == 'dev'
28
32
  Description-Content-Type: text/markdown
29
33
 
30
34
  # patchright-cli
@@ -174,6 +178,8 @@ patchright-cli check <ref> # Check checkbox
174
178
  patchright-cli uncheck <ref> # Uncheck checkbox
175
179
  patchright-cli drag <from> <to> # Drag and drop
176
180
  patchright-cli snapshot # Accessibility snapshot
181
+ patchright-cli snapshot -i # Interactive elements only (recommended)
182
+ patchright-cli snapshot --depth=3 # Limit depth
177
183
  patchright-cli snapshot <ref> # Snapshot element subtree
178
184
  patchright-cli snapshot --filename=f # Save to custom path
179
185
  patchright-cli eval <expr> # Run JavaScript
@@ -298,6 +304,17 @@ patchright-cli console warning # Filter by level
298
304
  patchright-cli console --clear # Clear after printing
299
305
  ```
300
306
 
307
+ ### Output
308
+ ```bash
309
+ patchright-cli --raw eval --file=s.js # Raw output (no page/snapshot decoration)
310
+ patchright-cli --raw snapshot > p.yml # Pipe raw snapshot to file
311
+ ```
312
+
313
+ ### Setup
314
+ ```bash
315
+ patchright-cli install --skills # Auto-install skills for detected AI agents
316
+ ```
317
+
301
318
  ### Sessions
302
319
  ```bash
303
320
  patchright-cli -s=mysession open https://example.com --persistent
@@ -372,6 +389,13 @@ Works with any AI coding agent that supports SKILL.md skills:
372
389
  | **Windsurf** | Copy SKILL.md to `.windsurf/skills/patchright-cli/` in your project |
373
390
  | **Aider** | Copy SKILL.md to `.aider/skills/patchright-cli/` in your project |
374
391
 
392
+ Or auto-install for all detected agents:
393
+
394
+ ```bash
395
+ pip install patchright-cli
396
+ patchright-cli install --skills
397
+ ```
398
+
375
399
  Or just tell your agent:
376
400
 
377
401
  > Install patchright-cli skill from https://raw.githubusercontent.com/AhaiMk01/patchright-cli/main/skills/patchright-cli/SKILL.md
@@ -398,9 +422,7 @@ patchright-cli aims for full command parity with [Microsoft's playwright-cli](ht
398
422
  | Feature | Reason |
399
423
  |---------|--------|
400
424
  | `--browser=firefox/webkit/msedge` | Patchright only supports Chromium/Chrome. Anti-detect patches are Chrome-specific. |
401
- | `--config=<file>` | No config file system. Options are passed as CLI flags. |
402
425
  | `--extension` | Browser extension connection not supported. Patchright uses CDP directly. |
403
- | `show` / `devtools-start` | DevTools are available natively in headed mode (default). |
404
426
  | `install` / `install-browser` | Use `python -m patchright install chromium` instead. |
405
427
 
406
428
  All other commands and options are fully supported.
@@ -416,6 +438,16 @@ All other commands and options are fully supported.
416
438
 
417
439
  ---
418
440
 
441
+ ## Credits
442
+
443
+ This project builds on the work of:
444
+
445
+ - **[Patchright](https://github.com/Kaliiiiiiiiii-Vinyzu/patchright)** by [@Kaliiiiiiiiii-Vinyzu](https://github.com/Kaliiiiiiiiii-Vinyzu) — the undetected Playwright fork that makes this possible. All anti-detect capabilities come from Patchright.
446
+ - **[playwright-cli](https://github.com/microsoft/playwright-cli)** by Microsoft — the original CLI that patchright-cli's command interface is modeled after.
447
+ - **[camoufox-cli](https://github.com/Bin-Huang/camoufox-cli)** by [@Bin-Huang](https://github.com/Bin-Huang) — inspiration for the CLI-first approach to anti-detect browser automation and the SKILL.md agent integration pattern.
448
+
449
+ ---
450
+
419
451
  ## License
420
452
 
421
453
  Apache 2.0 — same as [playwright-cli](https://github.com/microsoft/playwright-cli)
@@ -145,6 +145,8 @@ patchright-cli check <ref> # Check checkbox
145
145
  patchright-cli uncheck <ref> # Uncheck checkbox
146
146
  patchright-cli drag <from> <to> # Drag and drop
147
147
  patchright-cli snapshot # Accessibility snapshot
148
+ patchright-cli snapshot -i # Interactive elements only (recommended)
149
+ patchright-cli snapshot --depth=3 # Limit depth
148
150
  patchright-cli snapshot <ref> # Snapshot element subtree
149
151
  patchright-cli snapshot --filename=f # Save to custom path
150
152
  patchright-cli eval <expr> # Run JavaScript
@@ -269,6 +271,17 @@ patchright-cli console warning # Filter by level
269
271
  patchright-cli console --clear # Clear after printing
270
272
  ```
271
273
 
274
+ ### Output
275
+ ```bash
276
+ patchright-cli --raw eval --file=s.js # Raw output (no page/snapshot decoration)
277
+ patchright-cli --raw snapshot > p.yml # Pipe raw snapshot to file
278
+ ```
279
+
280
+ ### Setup
281
+ ```bash
282
+ patchright-cli install --skills # Auto-install skills for detected AI agents
283
+ ```
284
+
272
285
  ### Sessions
273
286
  ```bash
274
287
  patchright-cli -s=mysession open https://example.com --persistent
@@ -343,6 +356,13 @@ Works with any AI coding agent that supports SKILL.md skills:
343
356
  | **Windsurf** | Copy SKILL.md to `.windsurf/skills/patchright-cli/` in your project |
344
357
  | **Aider** | Copy SKILL.md to `.aider/skills/patchright-cli/` in your project |
345
358
 
359
+ Or auto-install for all detected agents:
360
+
361
+ ```bash
362
+ pip install patchright-cli
363
+ patchright-cli install --skills
364
+ ```
365
+
346
366
  Or just tell your agent:
347
367
 
348
368
  > Install patchright-cli skill from https://raw.githubusercontent.com/AhaiMk01/patchright-cli/main/skills/patchright-cli/SKILL.md
@@ -369,9 +389,7 @@ patchright-cli aims for full command parity with [Microsoft's playwright-cli](ht
369
389
  | Feature | Reason |
370
390
  |---------|--------|
371
391
  | `--browser=firefox/webkit/msedge` | Patchright only supports Chromium/Chrome. Anti-detect patches are Chrome-specific. |
372
- | `--config=<file>` | No config file system. Options are passed as CLI flags. |
373
392
  | `--extension` | Browser extension connection not supported. Patchright uses CDP directly. |
374
- | `show` / `devtools-start` | DevTools are available natively in headed mode (default). |
375
393
  | `install` / `install-browser` | Use `python -m patchright install chromium` instead. |
376
394
 
377
395
  All other commands and options are fully supported.
@@ -387,6 +405,16 @@ All other commands and options are fully supported.
387
405
 
388
406
  ---
389
407
 
408
+ ## Credits
409
+
410
+ This project builds on the work of:
411
+
412
+ - **[Patchright](https://github.com/Kaliiiiiiiiii-Vinyzu/patchright)** by [@Kaliiiiiiiiii-Vinyzu](https://github.com/Kaliiiiiiiiii-Vinyzu) — the undetected Playwright fork that makes this possible. All anti-detect capabilities come from Patchright.
413
+ - **[playwright-cli](https://github.com/microsoft/playwright-cli)** by Microsoft — the original CLI that patchright-cli's command interface is modeled after.
414
+ - **[camoufox-cli](https://github.com/Bin-Huang/camoufox-cli)** by [@Bin-Huang](https://github.com/Bin-Huang) — inspiration for the CLI-first approach to anti-detect browser automation and the SKILL.md agent integration pattern.
415
+
416
+ ---
417
+
390
418
  ## License
391
419
 
392
420
  Apache 2.0 — same as [playwright-cli](https://github.com/microsoft/playwright-cli)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "patchright-cli"
3
- version = "0.4.1"
3
+ version = "0.5.0"
4
4
  description = "Anti-detect browser automation CLI using Patchright (undetected Playwright fork)"
5
5
  license = "Apache-2.0"
6
6
  requires-python = ">=3.10"
@@ -44,12 +44,22 @@ build-backend = "hatchling.build"
44
44
  [tool.hatch.build.targets.wheel]
45
45
  packages = ["src/patchright_cli"]
46
46
 
47
+ [tool.hatch.build.targets.wheel.force-include]
48
+ "skills/patchright-cli" = "patchright_cli/_skills/patchright-cli"
49
+
47
50
  [tool.pytest.ini_options]
48
51
  asyncio_mode = "auto"
49
52
  markers = [
50
53
  "e2e: marks tests that launch a real browser",
51
54
  ]
52
55
 
56
+ [project.optional-dependencies]
57
+ dev = [
58
+ "pytest>=8.0",
59
+ "pytest-asyncio>=0.23",
60
+ "pre-commit",
61
+ ]
62
+
53
63
  [dependency-groups]
54
64
  dev = [
55
65
  "pytest>=8.0",
@@ -0,0 +1,348 @@
1
+ ---
2
+ name: patchright-cli
3
+ description: Anti-detect browser automation using Patchright (undetected Playwright fork). Use when you need to interact with websites that block regular Playwright/Chrome DevTools, such as Akamai/Cloudflare-protected sites. Provides the same command interface as playwright-cli but bypasses bot detection. Use this skill whenever the user asks to automate a browser, scrape a website, fill forms, log into sites, take screenshots, or do anything involving Chrome automation — especially if the target site has bot protection like Cloudflare or Akamai.
4
+ ---
5
+
6
+ # Anti-Detect Browser Automation with patchright-cli
7
+
8
+ patchright-cli drives a real Chrome browser that passes bot detection (Cloudflare, Akamai, etc.). It works as a CLI: you issue commands, get back page state. This is the tool to reach for whenever regular Playwright or Chrome DevTools gets blocked.
9
+
10
+ ## Quick start
11
+
12
+ ```bash
13
+ patchright-cli open https://example.com # launch browser + navigate
14
+ patchright-cli snapshot # get element refs
15
+ # read the snapshot YAML to find the right ref, then:
16
+ patchright-cli click e5 # interact by ref
17
+ patchright-cli fill e3 "search query" # type into an input
18
+ patchright-cli press Enter # press a key
19
+ patchright-cli screenshot # capture the page
20
+ patchright-cli close # done
21
+ ```
22
+
23
+ Every interaction follows: **open -> snapshot -> read refs -> interact -> snapshot again -> repeat**. Refs are ephemeral -- they change on every page update. If a ref fails, re-snapshot.
24
+
25
+ ## Command chaining
26
+
27
+ Commands can be chained with `&&`. The browser persists via a background daemon, so chaining is safe.
28
+
29
+ ```bash
30
+ # Chain when you don't need intermediate output
31
+ patchright-cli open https://example.com && patchright-cli screenshot
32
+
33
+ # Run separately when you need to read refs first
34
+ patchright-cli snapshot # read refs from output
35
+ patchright-cli click e5 # use discovered ref
36
+ ```
37
+
38
+ ## Global options
39
+
40
+ These go before the command:
41
+
42
+ ```bash
43
+ --headless # Run headless (default: headed -- headed is less detectable)
44
+ --persistent # Use persistent profile (keeps cookies/storage across sessions)
45
+ --profile=/path # Custom profile directory
46
+ --proxy=<url> # Proxy server (http, https, socks5) -- supports user:pass@host auth
47
+ -s=mysession # Named session (default: "default", or PATCHRIGHT_CLI_SESSION env var)
48
+ --port=9322 # Custom daemon port (default: 9321)
49
+ --config=<path> # Load options from JSON config file
50
+ --cdp=<url> # Attach to Chrome via CDP endpoint (use with `attach` command)
51
+ --device="iPhone 15" # Emulate a device
52
+ --viewport-size=1280x720 # Set viewport size
53
+ --locale=en-US # Browser locale
54
+ --timezone=America/New_York # Timezone ID
55
+ --geolocation=40.7,-74.0 # Geolocation override (lat,lon)
56
+ --user-agent=<ua> # Custom user agent string
57
+ --grant-permissions=geolocation,camera # Grant permissions at launch
58
+ --timeout-action=10000 # Default action timeout (ms)
59
+ --timeout-navigation=30000 # Default navigation timeout (ms)
60
+ --show-port=9322 # Dashboard port (default: 9322)
61
+ ```
62
+
63
+ ---
64
+
65
+ ## Core commands
66
+
67
+ ### Browser lifecycle
68
+
69
+ ```bash
70
+ open [url] # Launch browser (optionally navigate)
71
+ open --persistent # Keep cookies/storage between runs
72
+ open --headless # Headless mode
73
+ attach --cdp=<url> # Attach to existing Chrome via CDP
74
+ close # Close session
75
+ ```
76
+
77
+ ### Navigation
78
+
79
+ ```bash
80
+ goto <url> # Navigate to URL
81
+ go-back / go-forward # History navigation
82
+ reload # Reload page
83
+ url # Print current URL
84
+ title # Print page title
85
+ ```
86
+
87
+ ### Snapshots
88
+
89
+ ```bash
90
+ snapshot # Full page snapshot
91
+ snapshot <ref> # Subtree of a specific element
92
+ snapshot --depth=N # Limit depth
93
+ snapshot -i # Interactive elements only
94
+ ```
95
+
96
+ ### Interaction
97
+
98
+ ```bash
99
+ click <ref> # Left-click (smart: navigates links directly)
100
+ click <ref> right # Right-click
101
+ click <ref> --modifiers=Alt # Click with modifier keys
102
+ dblclick <ref> # Double-click
103
+ hover <ref> # Hover
104
+ drag <ref> <target-ref> # Drag element to target
105
+ ```
106
+
107
+ ### Form input
108
+
109
+ ```bash
110
+ fill <ref> "value" # Clear field and type value
111
+ fill <ref> "value" --submit # Fill and press Enter
112
+ type "text" # Type via keyboard (no target)
113
+ type "text" --submit # Type and press Enter
114
+ select <ref> "option" # Select dropdown option
115
+ check <ref> / uncheck <ref> # Checkbox/radio
116
+ ```
117
+
118
+ ### Text and screenshots
119
+
120
+ ```bash
121
+ text <ref> # Get text content by ref
122
+ text "css-selector" # Get text by CSS selector
123
+ screenshot # Page screenshot
124
+ screenshot <ref> # Element screenshot
125
+ screenshot --full-page # Full scrollable page
126
+ screenshot --filename=F # Custom filename
127
+ ```
128
+
129
+ ### Scroll, wait, and keyboard
130
+
131
+ ```bash
132
+ scroll <dx> <dy> # Scroll by pixels
133
+ scroll-to <ref> # Scroll element into view
134
+ wait <ms> # Wait N milliseconds
135
+ wait-for <ref> # Wait until element visible
136
+ wait-for <ref> --state=hidden # Wait until hidden
137
+ press <key> # Keypress (Enter, ArrowDown, etc.)
138
+ keydown <key> / keyup <key> # Hold/release key
139
+ ```
140
+
141
+ ### Mouse
142
+
143
+ ```bash
144
+ mousemove <x> <y> # Move to coordinates
145
+ mousedown / mouseup # Button down/up
146
+ mousewheel <dx> <dy> # Scroll wheel
147
+ ```
148
+
149
+ ### Tabs
150
+
151
+ ```bash
152
+ tab-list # List open tabs
153
+ tab-new <url> # Open new tab
154
+ tab-select <index> # Switch to tab
155
+ tab-close [index] # Close tab
156
+ ```
157
+
158
+ ### Dialogs
159
+
160
+ Dialogs must be pre-armed *before* the action that triggers them:
161
+
162
+ ```bash
163
+ dialog-accept # Accept next dialog
164
+ dialog-accept "OK" # Accept with text input
165
+ dialog-dismiss # Dismiss next dialog
166
+ ```
167
+
168
+ ### DevTools
169
+
170
+ ```bash
171
+ console # Show console messages
172
+ console warning # Filter by level
173
+ network # Show network requests
174
+ network --static # Include static assets
175
+ ```
176
+
177
+ ### Recording and capture
178
+
179
+ ```bash
180
+ screenshot / pdf # Static capture
181
+ video-start / video-stop # Video recording
182
+ tracing-start / tracing-stop # Playwright trace
183
+ codegen / codegen-stop # Record interactions as script
184
+ resize <w> <h> # Viewport resize
185
+ upload <file> [ref] # File upload
186
+ show # Live dashboard
187
+ ```
188
+
189
+ ### Storage
190
+
191
+ ```bash
192
+ cookie-list / cookie-get / cookie-set / cookie-delete / cookie-clear
193
+ cookie-export / cookie-import
194
+ localstorage-list / localstorage-get / localstorage-set / localstorage-delete / localstorage-clear
195
+ sessionstorage-list / sessionstorage-get / sessionstorage-set / sessionstorage-delete / sessionstorage-clear
196
+ state-save <file> / state-load <file>
197
+ ```
198
+
199
+ ### Network
200
+
201
+ ```bash
202
+ route "<pattern>" [options] # Mock requests (--status, --body, --content-type, --header)
203
+ route-list / unroute # Manage routes
204
+ network-state-set offline # Simulate offline
205
+ network-state-set online # Restore connectivity
206
+ ```
207
+
208
+ ### Sessions
209
+
210
+ ```bash
211
+ list # List active sessions
212
+ close-all # Close all sessions
213
+ kill-all # Force-kill all + stop daemon
214
+ delete-data # Delete session profile data
215
+ grant-permissions <perms> # Grant browser permissions
216
+ ```
217
+
218
+ ---
219
+
220
+ ## Common patterns
221
+
222
+ ### Login flow
223
+
224
+ ```bash
225
+ patchright-cli open https://example.com/login --persistent
226
+ patchright-cli snapshot
227
+ patchright-cli fill e3 "user@example.com"
228
+ patchright-cli fill e5 "password123"
229
+ patchright-cli click e8
230
+ patchright-cli snapshot
231
+ # With --persistent, cookies survive across sessions
232
+ ```
233
+
234
+ ### Extracting data
235
+
236
+ ```bash
237
+ patchright-cli open https://example.com/data
238
+ patchright-cli snapshot
239
+ cat > /tmp/extract.js << 'JSEOF'
240
+ JSON.stringify(
241
+ [...document.querySelectorAll('table tr')].map(row =>
242
+ [...row.cells].map(cell => cell.textContent.trim())
243
+ )
244
+ )
245
+ JSEOF
246
+ patchright-cli eval --file=/tmp/extract.js
247
+ ```
248
+
249
+ ### Using a proxy
250
+
251
+ ```bash
252
+ patchright-cli --proxy=http://host:port open https://example.com
253
+ patchright-cli --proxy=socks5://host:port open https://example.com
254
+ patchright-cli --proxy=http://user:pass@host:port open https://example.com
255
+ ```
256
+
257
+ ### Handling dialogs
258
+
259
+ ```bash
260
+ patchright-cli dialog-accept # Arm before triggering action
261
+ patchright-cli click e5 # This click triggers the dialog
262
+ ```
263
+
264
+ ### Waiting for dynamic content
265
+
266
+ ```bash
267
+ patchright-cli wait-for e12 # Wait for element
268
+ patchright-cli wait 1000 # Fixed wait
269
+ # For custom conditions, use run-code (see references/running-code.md)
270
+ ```
271
+
272
+ ---
273
+
274
+ ## Anti-detect notes
275
+
276
+ - Uses real Chrome (not Chromium) -- this is what makes it undetectable
277
+ - Patchright patches `navigator.webdriver` and other detection vectors automatically
278
+ - Headed by default -- headless mode is more detectable, use only when necessary
279
+ - No custom user-agent or headers by default -- preserves Chrome's natural fingerprint
280
+ - Persistent profiles maintain realistic browser history and cookies
281
+ - The daemon architecture means Chrome stays running between commands, behaving like a real user's browser
282
+ - `attach --cdp` lets you connect to an existing Chrome instance
283
+
284
+ ## Config files
285
+
286
+ Create `.patchright-cli/config.json` in your project directory (auto-discovered) or pass `--config=<path>`:
287
+
288
+ ```json
289
+ {
290
+ "headless": false,
291
+ "persistent": true,
292
+ "proxy": "http://proxy:8080",
293
+ "device": "iPhone 15",
294
+ "locale": "en-US",
295
+ "timezone": "America/New_York"
296
+ }
297
+ ```
298
+
299
+ CLI flags always override config file values.
300
+
301
+ ## Installation
302
+
303
+ ### CLI tool
304
+
305
+ ```bash
306
+ # Recommended -- always runs latest version
307
+ uvx patchright-cli <command>
308
+
309
+ # Or install globally
310
+ pip install patchright-cli
311
+ ```
312
+
313
+ ### Skill (for AI coding agents)
314
+
315
+ Install the skill so your agent knows how to use patchright-cli. The same command also works to update to the latest version.
316
+
317
+ **macOS / Linux (bash/zsh):**
318
+
319
+ | Agent | Install / update command |
320
+ |-------|--------------------------|
321
+ | **Claude Code** | `mkdir -p ~/.claude/skills/patchright-cli && curl -sL https://raw.githubusercontent.com/AhaiMk01/patchright-cli/main/skills/patchright-cli/SKILL.md -o ~/.claude/skills/patchright-cli/SKILL.md` |
322
+ | **Gemini CLI** | `mkdir -p ~/.gemini/skills/patchright-cli && curl -sL https://raw.githubusercontent.com/AhaiMk01/patchright-cli/main/skills/patchright-cli/SKILL.md -o ~/.gemini/skills/patchright-cli/SKILL.md` |
323
+ | **Codex CLI** | `mkdir -p ~/.codex/skills/patchright-cli && curl -sL https://raw.githubusercontent.com/AhaiMk01/patchright-cli/main/skills/patchright-cli/SKILL.md -o ~/.codex/skills/patchright-cli/SKILL.md` |
324
+ | **OpenCode** | `mkdir -p ~/.opencode/skills/patchright-cli && curl -sL https://raw.githubusercontent.com/AhaiMk01/patchright-cli/main/skills/patchright-cli/SKILL.md -o ~/.opencode/skills/patchright-cli/SKILL.md` |
325
+
326
+ **Windows (PowerShell):**
327
+
328
+ | Agent | Install / update command |
329
+ |-------|--------------------------|
330
+ | **Claude Code** | `New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\.claude\skills\patchright-cli" | Out-Null; Invoke-WebRequest -Uri "https://raw.githubusercontent.com/AhaiMk01/patchright-cli/main/skills/patchright-cli/SKILL.md" -OutFile "$env:USERPROFILE\.claude\skills\patchright-cli\SKILL.md"` |
331
+ | **Gemini CLI** | `New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\.gemini\skills\patchright-cli" | Out-Null; Invoke-WebRequest -Uri "https://raw.githubusercontent.com/AhaiMk01/patchright-cli/main/skills/patchright-cli/SKILL.md" -OutFile "$env:USERPROFILE\.gemini\skills\patchright-cli\SKILL.md"` |
332
+ | **Codex CLI** | `New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\.codex\skills\patchright-cli" | Out-Null; Invoke-WebRequest -Uri "https://raw.githubusercontent.com/AhaiMk01/patchright-cli/main/skills/patchright-cli/SKILL.md" -OutFile "$env:USERPROFILE\.codex\skills\patchright-cli\SKILL.md"` |
333
+ | **OpenCode** | `New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\.opencode\skills\patchright-cli" | Out-Null; Invoke-WebRequest -Uri "https://raw.githubusercontent.com/AhaiMk01/patchright-cli/main/skills/patchright-cli/SKILL.md" -OutFile "$env:USERPROFILE\.opencode\skills\patchright-cli\SKILL.md"` |
334
+
335
+ **IDE-based agents (Cursor / Windsurf / Aider):** Copy `SKILL.md` to `.<tool>/skills/patchright-cli/` in your project.
336
+
337
+ **Or just tell your agent:**
338
+ > Install patchright-cli skill from https://raw.githubusercontent.com/AhaiMk01/patchright-cli/main/skills/patchright-cli/SKILL.md
339
+
340
+ ## Specific tasks
341
+
342
+ * **Snapshots and element refs** [references/snapshot-refs.md](references/snapshot-refs.md)
343
+ * **Browser session management** [references/session-management.md](references/session-management.md)
344
+ * **Request mocking** [references/request-mocking.md](references/request-mocking.md)
345
+ * **Storage state (cookies, localStorage)** [references/storage-state.md](references/storage-state.md)
346
+ * **Running JavaScript** [references/running-code.md](references/running-code.md)
347
+ * **Tracing** [references/tracing.md](references/tracing.md)
348
+ * **Video recording & capture** [references/video-recording.md](references/video-recording.md)