patchright-cli 0.2.0__tar.gz → 0.3.1__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.
@@ -8,6 +8,9 @@ on:
8
8
  permissions:
9
9
  contents: write
10
10
 
11
+ env:
12
+ FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
13
+
11
14
  jobs:
12
15
  build:
13
16
  runs-on: ubuntu-latest
@@ -15,7 +18,7 @@ jobs:
15
18
  - uses: actions/checkout@v4
16
19
 
17
20
  - name: Install uv
18
- uses: astral-sh/setup-uv@v4
21
+ uses: astral-sh/setup-uv@v5
19
22
 
20
23
  - name: Set up Python
21
24
  run: uv python install 3.12
@@ -43,7 +46,7 @@ jobs:
43
46
  path: dist/
44
47
 
45
48
  - name: Install uv
46
- uses: astral-sh/setup-uv@v4
49
+ uses: astral-sh/setup-uv@v5
47
50
 
48
51
  - name: Publish to PyPI
49
52
  run: uv publish
@@ -0,0 +1,55 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Project Overview
6
+
7
+ patchright-cli is an anti-detect browser automation CLI built on [Patchright](https://github.com/kaliiiiiiiiii/patchright-python) (undetected Playwright fork). It provides the same command interface as Microsoft's playwright-cli but bypasses bot detection (Akamai, Cloudflare, etc.).
8
+
9
+ ## Development Setup
10
+
11
+ ```bash
12
+ uv venv && uv pip install -e .
13
+ python -m patchright install chromium
14
+ pre-commit install
15
+ ```
16
+
17
+ ## Commands
18
+
19
+ ```bash
20
+ # Lint (pre-commit runs ruff --fix + ruff-format)
21
+ pre-commit run --all-files
22
+
23
+ # Run the CLI directly
24
+ python -m patchright_cli <command> [args...]
25
+ # or after install:
26
+ patchright-cli <command> [args...]
27
+ ```
28
+
29
+ There are no automated tests yet — changes are tested manually via the CLI.
30
+
31
+ ## Architecture
32
+
33
+ Three-component client-daemon-browser design:
34
+
35
+ ```
36
+ CLI (cli.py) --TCP:9321--> Daemon (daemon.py) --Patchright--> Chrome
37
+ ```
38
+
39
+ - **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
+
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.
42
+
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.
44
+
45
+ ## Key Design Decisions
46
+
47
+ - Always uses persistent browser context (`launch_persistent_context`) with real Chrome (`channel="chrome"`), not Chromium
48
+ - Headed by default (headless is more detectable)
49
+ - Default daemon port: 9321, profiles stored at `~/.patchright-cli/profiles/<session-name>`
50
+ - CLI-daemon protocol: length-prefixed (4-byte big-endian `!I`) JSON over TCP
51
+ - CLI parses argv manually in `main()` — click is only used for `click.echo()`, not subcommands. New commands must be added to both `COMMANDS_HELP` dict and the `handle_command()` if/elif chain in daemon.py
52
+ - Version must be updated in both `pyproject.toml` and `src/patchright_cli/__init__.py` (then run `uv lock` to sync the lock file)
53
+ - `python -m patchright_cli` works via `__main__.py`
54
+ - Uses hatchling as build backend, ruff for linting (line-length=120, target py310)
55
+ - Ruff rules: E, F, I, W, UP, B, SIM (ignores E501, SIM105, E402)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: patchright-cli
3
- Version: 0.2.0
3
+ Version: 0.3.1
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
@@ -78,25 +78,22 @@ curl -s https://raw.githubusercontent.com/AhaiMk01/patchright-cli/main/docs/inst
78
78
  > [!IMPORTANT]
79
79
  > **Requirements:** Python 3.10+ and Google Chrome
80
80
 
81
- <details>
82
- <summary><b>Manual Install</b></summary>
83
-
84
81
  ```bash
85
- # 1. Install the package
86
- pip install patchright-cli # or: uv tool install patchright-cli
82
+ # Recommended — always runs latest version, no install needed
83
+ uvx patchright-cli open https://example.com
84
+ ```
87
85
 
88
- # 2. Install the Patchright browser (fallback if Chrome is not found)
89
- python -m patchright install chromium
86
+ <details>
87
+ <summary><b>Other install methods</b></summary>
90
88
 
91
- # 3. Verify
89
+ ```bash
90
+ # Via pip
91
+ pip install patchright-cli
92
92
  patchright-cli open https://example.com
93
93
  patchright-cli close
94
- ```
95
94
 
96
- Or run without installing (like npx):
97
-
98
- ```bash
99
- uvx patchright-cli open https://example.com
95
+ # Update
96
+ pip install --upgrade patchright-cli
100
97
  ```
101
98
 
102
99
  **From source:**
@@ -167,16 +164,21 @@ patchright-cli click <ref> --modifiers=Alt,Shift
167
164
  patchright-cli dblclick <ref> # Double-click
168
165
  patchright-cli dblclick <ref> --modifiers=Shift
169
166
  patchright-cli fill <ref> <value> # Fill text input
167
+ patchright-cli fill <ref> <value> --submit # Fill and press Enter
170
168
  patchright-cli type <text> # Type via keyboard
169
+ patchright-cli type <text> --submit # Type and press Enter
171
170
  patchright-cli hover <ref> # Hover over element
172
171
  patchright-cli select <ref> <value> # Select dropdown option
173
172
  patchright-cli check <ref> # Check checkbox
174
173
  patchright-cli uncheck <ref> # Uncheck checkbox
175
174
  patchright-cli drag <from> <to> # Drag and drop
176
175
  patchright-cli snapshot # Accessibility snapshot
176
+ patchright-cli snapshot <ref> # Snapshot element subtree
177
177
  patchright-cli snapshot --filename=f # Save to custom path
178
178
  patchright-cli eval <expr> # Run JavaScript
179
+ patchright-cli eval --file=script.js # Run JS from file
179
180
  patchright-cli run-code <code> # Run JS with return value
181
+ patchright-cli run-code --file=f.js # Run JS from file
180
182
  patchright-cli screenshot # Page screenshot
181
183
  patchright-cli screenshot --full-page # Full scrollable page
182
184
  patchright-cli screenshot <ref> # Element screenshot
@@ -269,18 +271,30 @@ patchright-cli unroute "**/*.jpg"
269
271
  patchright-cli unroute # Remove all routes
270
272
  ```
271
273
 
272
- ### Tracing / PDF
274
+ ### Tracing / Video / PDF
273
275
  ```bash
274
276
  patchright-cli tracing-start
275
277
  patchright-cli tracing-stop # Saves .zip trace file
278
+ patchright-cli video-start # Start video recording (CDP screencast)
279
+ patchright-cli video-stop # Stop and save video (requires ffmpeg for .webm)
280
+ patchright-cli video-stop --filename=recording.webm
276
281
  patchright-cli pdf --filename=page.pdf
277
282
  ```
278
283
 
284
+ ### Network
285
+ ```bash
286
+ patchright-cli network # Network request log
287
+ patchright-cli network --static # Include static resources
288
+ patchright-cli network --clear # Clear log after printing
289
+ patchright-cli network-state-set offline # Simulate offline mode
290
+ patchright-cli network-state-set online # Restore connectivity
291
+ ```
292
+
279
293
  ### DevTools
280
294
  ```bash
281
295
  patchright-cli console # All console messages
282
296
  patchright-cli console warning # Filter by level
283
- patchright-cli network # Network request log
297
+ patchright-cli console --clear # Clear after printing
284
298
  ```
285
299
 
286
300
  ### Sessions
@@ -50,25 +50,22 @@ curl -s https://raw.githubusercontent.com/AhaiMk01/patchright-cli/main/docs/inst
50
50
  > [!IMPORTANT]
51
51
  > **Requirements:** Python 3.10+ and Google Chrome
52
52
 
53
- <details>
54
- <summary><b>Manual Install</b></summary>
55
-
56
53
  ```bash
57
- # 1. Install the package
58
- pip install patchright-cli # or: uv tool install patchright-cli
54
+ # Recommended — always runs latest version, no install needed
55
+ uvx patchright-cli open https://example.com
56
+ ```
59
57
 
60
- # 2. Install the Patchright browser (fallback if Chrome is not found)
61
- python -m patchright install chromium
58
+ <details>
59
+ <summary><b>Other install methods</b></summary>
62
60
 
63
- # 3. Verify
61
+ ```bash
62
+ # Via pip
63
+ pip install patchright-cli
64
64
  patchright-cli open https://example.com
65
65
  patchright-cli close
66
- ```
67
66
 
68
- Or run without installing (like npx):
69
-
70
- ```bash
71
- uvx patchright-cli open https://example.com
67
+ # Update
68
+ pip install --upgrade patchright-cli
72
69
  ```
73
70
 
74
71
  **From source:**
@@ -139,16 +136,21 @@ patchright-cli click <ref> --modifiers=Alt,Shift
139
136
  patchright-cli dblclick <ref> # Double-click
140
137
  patchright-cli dblclick <ref> --modifiers=Shift
141
138
  patchright-cli fill <ref> <value> # Fill text input
139
+ patchright-cli fill <ref> <value> --submit # Fill and press Enter
142
140
  patchright-cli type <text> # Type via keyboard
141
+ patchright-cli type <text> --submit # Type and press Enter
143
142
  patchright-cli hover <ref> # Hover over element
144
143
  patchright-cli select <ref> <value> # Select dropdown option
145
144
  patchright-cli check <ref> # Check checkbox
146
145
  patchright-cli uncheck <ref> # Uncheck checkbox
147
146
  patchright-cli drag <from> <to> # Drag and drop
148
147
  patchright-cli snapshot # Accessibility snapshot
148
+ patchright-cli snapshot <ref> # Snapshot element subtree
149
149
  patchright-cli snapshot --filename=f # Save to custom path
150
150
  patchright-cli eval <expr> # Run JavaScript
151
+ patchright-cli eval --file=script.js # Run JS from file
151
152
  patchright-cli run-code <code> # Run JS with return value
153
+ patchright-cli run-code --file=f.js # Run JS from file
152
154
  patchright-cli screenshot # Page screenshot
153
155
  patchright-cli screenshot --full-page # Full scrollable page
154
156
  patchright-cli screenshot <ref> # Element screenshot
@@ -241,18 +243,30 @@ patchright-cli unroute "**/*.jpg"
241
243
  patchright-cli unroute # Remove all routes
242
244
  ```
243
245
 
244
- ### Tracing / PDF
246
+ ### Tracing / Video / PDF
245
247
  ```bash
246
248
  patchright-cli tracing-start
247
249
  patchright-cli tracing-stop # Saves .zip trace file
250
+ patchright-cli video-start # Start video recording (CDP screencast)
251
+ patchright-cli video-stop # Stop and save video (requires ffmpeg for .webm)
252
+ patchright-cli video-stop --filename=recording.webm
248
253
  patchright-cli pdf --filename=page.pdf
249
254
  ```
250
255
 
256
+ ### Network
257
+ ```bash
258
+ patchright-cli network # Network request log
259
+ patchright-cli network --static # Include static resources
260
+ patchright-cli network --clear # Clear log after printing
261
+ patchright-cli network-state-set offline # Simulate offline mode
262
+ patchright-cli network-state-set online # Restore connectivity
263
+ ```
264
+
251
265
  ### DevTools
252
266
  ```bash
253
267
  patchright-cli console # All console messages
254
268
  patchright-cli console warning # Filter by level
255
- patchright-cli network # Network request log
269
+ patchright-cli console --clear # Clear after printing
256
270
  ```
257
271
 
258
272
  ### Sessions
@@ -7,50 +7,56 @@
7
7
 
8
8
  ## Install
9
9
 
10
- ### Step 1: Install the package
10
+ ### Step 1: Ensure uv is installed
11
11
 
12
- ```bash
13
- pip install patchright-cli
14
- ```
15
-
16
- Or with uv (recommended):
12
+ uv is the recommended Python package manager. Check if it's installed:
17
13
 
18
14
  ```bash
19
- uv tool install patchright-cli
15
+ uv --version
20
16
  ```
21
17
 
22
- ### Step 2: Install the Patchright browser
23
-
24
- Patchright needs to download its patched Chromium binary on first use:
18
+ If not installed:
25
19
 
26
20
  ```bash
27
21
  # macOS / Linux
28
- python -m patchright install chromium
22
+ curl -LsSf https://astral.sh/uv/install.sh | sh
29
23
 
30
24
  # Windows (PowerShell)
31
- python -m patchright install chromium
25
+ powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
26
+ ```
27
+
28
+ ### Step 2: Run patchright-cli
29
+
30
+ With uvx (recommended — always uses the latest version, no install needed):
32
31
 
33
- # Or if using uv
34
- uv run python -m patchright install chromium
32
+ ```bash
33
+ uvx patchright-cli open https://example.com
34
+ uvx patchright-cli snapshot
35
+ uvx patchright-cli close
35
36
  ```
36
37
 
37
- > **Note:** If you have Google Chrome installed, patchright-cli will use it directly via `channel="chrome"` for maximum stealth. The Chromium install above is a fallback.
38
+ > **Note:** If you have Google Chrome installed, patchright-cli will use it directly via `channel="chrome"` for maximum stealth. If Chrome is not found, install the Patchright fallback browser: `uvx patchright install chromium`
38
39
 
39
40
  ### Step 3: Verify
40
41
 
41
42
  ```bash
42
- patchright-cli --version
43
- patchright-cli open https://example.com
44
- patchright-cli eval "document.title"
45
- patchright-cli close
43
+ uvx patchright-cli --version
44
+ uvx patchright-cli open https://example.com
45
+ uvx patchright-cli eval "document.title"
46
+ uvx patchright-cli close
46
47
  ```
47
48
 
48
- ### Quick one-liner (no install)
49
+ <details>
50
+ <summary><b>Alternative: pip install</b></summary>
49
51
 
50
52
  ```bash
51
- uvx patchright-cli open https://example.com
53
+ pip install patchright-cli
54
+ patchright-cli open https://example.com
55
+ patchright-cli close
52
56
  ```
53
57
 
58
+ </details>
59
+
54
60
  ### Troubleshooting
55
61
 
56
62
  If you see `browser not found` errors:
@@ -62,16 +68,13 @@ google-chrome --version # Linux
62
68
  reg query "HKLM\SOFTWARE\Google\Chrome\BLBeacon" /v version # Windows
63
69
 
64
70
  # If no Chrome, install the Patchright browser
65
- python -m patchright install chromium
71
+ uvx patchright install chromium
66
72
  ```
67
73
 
68
74
  If you see `patchright-cli: command not found`:
69
75
 
70
76
  ```bash
71
- # Ensure pip scripts directory is in PATH
72
- python -m patchright_cli --help
73
-
74
- # Or use uvx (no PATH needed)
77
+ # Use uvx instead (no install or PATH needed)
75
78
  uvx patchright-cli --help
76
79
  ```
77
80
 
@@ -148,25 +151,25 @@ curl -sL https://raw.githubusercontent.com/AhaiMk01/patchright-cli/main/skills/p
148
151
 
149
152
  ```bash
150
153
  # Open an anti-bot-protected site
151
- patchright-cli open https://protected-site.com
154
+ uvx patchright-cli open https://protected-site.com
152
155
 
153
156
  # Take a snapshot to see interactive elements
154
- patchright-cli snapshot
157
+ uvx patchright-cli snapshot
155
158
 
156
159
  # Interact with elements using refs from the snapshot
157
- patchright-cli fill e3 "username"
158
- patchright-cli fill e4 "password"
159
- patchright-cli click e5
160
+ uvx patchright-cli fill e3 "username"
161
+ uvx patchright-cli fill e4 "password"
162
+ uvx patchright-cli click e5
160
163
 
161
164
  # Save login state for reuse
162
- patchright-cli state-save auth.json
165
+ uvx patchright-cli state-save auth.json
163
166
 
164
167
  # Later, restore the session
165
- patchright-cli open https://protected-site.com --persistent
166
- patchright-cli state-load auth.json
168
+ uvx patchright-cli open https://protected-site.com --persistent
169
+ uvx patchright-cli state-load auth.json
167
170
 
168
171
  # Close when done
169
- patchright-cli close
172
+ uvx patchright-cli close
170
173
  ```
171
174
 
172
175
  ## All Commands
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "patchright-cli"
3
- version = "0.2.0"
3
+ version = "0.3.1"
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"