patchright-cli 0.1.0__tar.gz → 0.3.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.
@@ -5,3 +5,4 @@ __pycache__/
5
5
  *.egg-info/
6
6
  dist/
7
7
  build/
8
+ docs/reddit-post.md
@@ -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)
@@ -0,0 +1,44 @@
1
+ # Contributing to patchright-cli
2
+
3
+ Thanks for your interest in contributing! Here's how to get started.
4
+
5
+ ## Getting Started
6
+
7
+ ```bash
8
+ git clone https://github.com/AhaiMk01/patchright-cli.git
9
+ cd patchright-cli
10
+ uv venv && uv pip install -e .
11
+ python -m patchright install chromium
12
+ pre-commit install
13
+ ```
14
+
15
+ ## Making Changes
16
+
17
+ 1. Fork the repo and create a branch from `main`
18
+ 2. Make your changes
19
+ 3. Run `pre-commit run --all-files` to check linting
20
+ 4. Test your changes manually with `patchright-cli`
21
+ 5. Commit and open a PR
22
+
23
+ ## What to Contribute
24
+
25
+ - Bug fixes
26
+ - New commands (check playwright-cli for parity gaps)
27
+ - Snapshot accuracy improvements
28
+ - Platform compatibility fixes (Windows/macOS/Linux)
29
+ - Documentation improvements
30
+ - Tests
31
+
32
+ ## Code Style
33
+
34
+ - Python 3.10+
35
+ - Formatted with [Ruff](https://github.com/astral-sh/ruff) (enforced via pre-commit)
36
+ - Keep the daemon lightweight — avoid heavy dependencies
37
+
38
+ ## Reporting Issues
39
+
40
+ Open an issue with:
41
+ - What you expected
42
+ - What happened
43
+ - Steps to reproduce
44
+ - OS and Python version
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: patchright-cli
3
- Version: 0.1.0
3
+ Version: 0.3.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
@@ -28,59 +28,87 @@ Description-Content-Type: text/markdown
28
28
 
29
29
  # patchright-cli
30
30
 
31
- <!-- badges (hidden until PyPI publish)
32
31
  [![PyPI version](https://img.shields.io/pypi/v/patchright-cli?color=blue&label=PyPI)](https://pypi.org/project/patchright-cli/)
33
32
  [![Python](https://img.shields.io/pypi/pyversions/patchright-cli?label=Python)](https://pypi.org/project/patchright-cli/)
34
- [![License](https://img.shields.io/github/license/AhaiMk01/patchright-cli?color=green)](LICENSE)
35
33
  [![Downloads](https://img.shields.io/pypi/dm/patchright-cli?color=orange&label=Downloads)](https://pypi.org/project/patchright-cli/)
36
- -->
34
+ [![License](https://img.shields.io/github/license/AhaiMk01/patchright-cli?color=green)](LICENSE)
35
+ [![CI](https://img.shields.io/github/actions/workflow/status/AhaiMk01/patchright-cli/publish.yml?label=CI)](https://github.com/AhaiMk01/patchright-cli/actions)
36
+ [![GitHub stars](https://img.shields.io/github/stars/AhaiMk01/patchright-cli?style=flat&label=Stars)](https://github.com/AhaiMk01/patchright-cli)
37
+ [![GitHub issues](https://img.shields.io/github/issues/AhaiMk01/patchright-cli?label=Issues)](https://github.com/AhaiMk01/patchright-cli/issues)
38
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
37
39
 
38
40
  Anti-detect browser automation CLI. Same command interface as [Microsoft's playwright-cli](https://github.com/microsoft/playwright-cli) but using [Patchright](https://github.com/kaliiiiiiiiii/patchright-python) (undetected Playwright fork) to bypass bot detection.
39
41
 
40
- ## Why
41
-
42
- Regular Playwright and Chrome DevTools get blocked by Akamai, Cloudflare, and other anti-bot systems. Patchright patches Chromium's detection vectors (`navigator.webdriver`, WebGL fingerprints, etc.) so automated browsers look like real users.
42
+ [Install](#install) · [Quick Start](#quick-start) · [Commands](#-commands) · [Snapshots](#snapshots) · [Agent Integration](#agent-integration)
43
43
 
44
- This CLI wraps Patchright in the same command interface as playwright-cli, so AI agents (Claude Code, etc.) can automate anti-bot-protected sites with the same workflow they'd use for regular Playwright.
44
+ ### Highlights
45
45
 
46
- ## Install
46
+ | | Feature |
47
+ |---|---|
48
+ | :shield: | Bypasses Akamai, Cloudflare, and other anti-bot systems |
49
+ | :rocket: | Same command interface as playwright-cli — zero learning curve |
50
+ | :robot: | Built for AI agents (Claude Code, Codex, etc.) with YAML snapshots |
51
+ | :zap: | Daemon architecture — browser stays open between commands |
52
+ | :package: | `pip install` / `uvx` — no Docker, no config files |
53
+ | :lock: | Persistent profiles for maintaining login sessions |
47
54
 
48
- ### For Humans
55
+ ---
49
56
 
50
- Just tell your AI agent:
57
+ ## Install
51
58
 
59
+ > [!TIP]
60
+ > **Just paste this into your AI coding agent — it will do the rest:**
61
+ >
62
+ > ```
52
63
  > Install and set up patchright-cli by following the instructions here:
53
64
  > https://raw.githubusercontent.com/AhaiMk01/patchright-cli/main/docs/installation.md
65
+ > ```
66
+ >
67
+ > Your agent handles the install, browser setup, and skill configuration automatically.
54
68
 
55
- Seriously — let the agent do it. It handles configs better than you.
56
-
57
- ### For LLM Agents
69
+ <details>
70
+ <summary><b>For LLM Agents</b></summary>
58
71
 
59
72
  ```bash
60
73
  curl -s https://raw.githubusercontent.com/AhaiMk01/patchright-cli/main/docs/installation.md
61
74
  ```
62
75
 
63
- ### Manual Install
76
+ </details>
77
+
78
+ > [!IMPORTANT]
79
+ > **Requirements:** Python 3.10+ and Google Chrome
64
80
 
65
81
  ```bash
66
- # With pip
67
- pip install patchright-cli
82
+ # Recommended — always runs latest version, no install needed
83
+ uvx patchright-cli open https://example.com
84
+ ```
68
85
 
69
- # With uv (recommended)
70
- uv tool install patchright-cli
86
+ <details>
87
+ <summary><b>Other install methods</b></summary>
71
88
 
72
- # Run without installing (like npx)
73
- uvx patchright-cli open https://example.com
89
+ ```bash
90
+ # Via pip
91
+ pip install patchright-cli
92
+ patchright-cli open https://example.com
93
+ patchright-cli close
94
+
95
+ # Update
96
+ pip install --upgrade patchright-cli
74
97
  ```
75
98
 
76
- ### From Source
99
+ **From source:**
77
100
 
78
101
  ```bash
79
102
  git clone https://github.com/AhaiMk01/patchright-cli.git
80
103
  cd patchright-cli
81
104
  uv venv && uv pip install -e .
105
+ python -m patchright install chromium
82
106
  ```
83
107
 
108
+ </details>
109
+
110
+ ---
111
+
84
112
  ## Quick Start
85
113
 
86
114
  ```bash
@@ -102,38 +130,57 @@ patchright-cli screenshot
102
130
  patchright-cli close
103
131
  ```
104
132
 
133
+ ---
134
+
105
135
  ## Architecture
106
136
 
107
137
  ```mermaid
108
138
  graph LR
109
- A[CLI Client<br/>cli.py] -->|TCP/JSON<br/>localhost:9321| B[Daemon<br/>daemon.py]
110
- B -->|Patchright<br/>CDP| C[Chrome<br/>stealth]
139
+ A[CLI] -->|TCP:9321| B[Daemon]
140
+ B -->|Patchright| C[Chrome]
111
141
  ```
112
142
 
113
- - **Daemon** (`daemon.py`): Long-running Python process managing browser sessions via Patchright. Listens on `localhost:9321`. Auto-starts on first `open` command.
114
- - **CLI** (`cli.py`): Thin client. Parses args, sends JSON to daemon, prints result. Each invocation connects and disconnects — the browser stays open between commands.
115
- - **Snapshot** (`snapshot.py`): Walks the DOM with `TreeWalker` in document order, assigns `data-patchright-ref` attributes, outputs a flat YAML list of interactive elements.
143
+ | Component | Role |
144
+ |-----------|------|
145
+ | **Daemon** (`daemon.py`) | Long-running process managing browser sessions via Patchright. Auto-starts on first `open`. |
146
+ | **CLI** (`cli.py`) | Thin client — connects, sends command, prints result, disconnects. Browser stays open. |
147
+ | **Snapshot** (`snapshot.py`) | `TreeWalker`-based DOM scan assigning `data-patchright-ref` attributes for element targeting. |
148
+
149
+ ---
116
150
 
117
- ## Commands
151
+ <details>
152
+ <summary><h2>📖 Commands</h2></summary>
118
153
 
119
154
  ### Core
120
155
  ```bash
121
156
  patchright-cli open [url] # Launch browser
122
157
  patchright-cli open --persistent # With persistent profile
158
+ patchright-cli open --headless # Run headless
159
+ patchright-cli open --profile=<path> # Custom profile directory
123
160
  patchright-cli goto <url> # Navigate
124
161
  patchright-cli click <ref> # Click element
162
+ patchright-cli click <ref> right # Right-click
163
+ patchright-cli click <ref> --modifiers=Alt,Shift
125
164
  patchright-cli dblclick <ref> # Double-click
165
+ patchright-cli dblclick <ref> --modifiers=Shift
126
166
  patchright-cli fill <ref> <value> # Fill text input
167
+ patchright-cli fill <ref> <value> --submit # Fill and press Enter
127
168
  patchright-cli type <text> # Type via keyboard
169
+ patchright-cli type <text> --submit # Type and press Enter
128
170
  patchright-cli hover <ref> # Hover over element
129
171
  patchright-cli select <ref> <value> # Select dropdown option
130
172
  patchright-cli check <ref> # Check checkbox
131
173
  patchright-cli uncheck <ref> # Uncheck checkbox
132
174
  patchright-cli drag <from> <to> # Drag and drop
133
175
  patchright-cli snapshot # Accessibility snapshot
176
+ patchright-cli snapshot <ref> # Snapshot element subtree
134
177
  patchright-cli snapshot --filename=f # Save to custom path
135
178
  patchright-cli eval <expr> # Run JavaScript
136
- patchright-cli screenshot # Full page screenshot
179
+ patchright-cli eval --file=script.js # Run JS from file
180
+ patchright-cli run-code <code> # Run JS with return value
181
+ patchright-cli run-code --file=f.js # Run JS from file
182
+ patchright-cli screenshot # Page screenshot
183
+ patchright-cli screenshot --full-page # Full scrollable page
137
184
  patchright-cli screenshot <ref> # Element screenshot
138
185
  patchright-cli screenshot --filename=f # Save to custom path
139
186
  patchright-cli close # Close session
@@ -189,9 +236,11 @@ patchright-cli state-load <file> # Restore saved state
189
236
  # Cookies
190
237
  patchright-cli cookie-list
191
238
  patchright-cli cookie-list --domain=example.com
239
+ patchright-cli cookie-list --path=/api
192
240
  patchright-cli cookie-get <name>
193
241
  patchright-cli cookie-set <name> <value>
194
242
  patchright-cli cookie-set <name> <value> --domain=example.com --httpOnly --secure
243
+ patchright-cli cookie-set <name> <value> --path=/ --sameSite=Lax --expires=1735689600
195
244
  patchright-cli cookie-delete <name>
196
245
  patchright-cli cookie-clear
197
246
 
@@ -214,23 +263,38 @@ patchright-cli sessionstorage-clear
214
263
  ```bash
215
264
  patchright-cli route "**/*.jpg" --status=404
216
265
  patchright-cli route "https://api.example.com/**" --body='{"mock":true}'
266
+ patchright-cli route "**/*" --content-type=application/json --body='{"ok":true}'
267
+ patchright-cli route "**/*" --header=X-Custom:value
268
+ patchright-cli route "**/*" --remove-header=Content-Type
217
269
  patchright-cli route-list
218
270
  patchright-cli unroute "**/*.jpg"
219
271
  patchright-cli unroute # Remove all routes
220
272
  ```
221
273
 
222
- ### Tracing / PDF
274
+ ### Tracing / Video / PDF
223
275
  ```bash
224
276
  patchright-cli tracing-start
225
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
226
281
  patchright-cli pdf --filename=page.pdf
227
282
  ```
228
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
+
229
293
  ### DevTools
230
294
  ```bash
231
295
  patchright-cli console # All console messages
232
296
  patchright-cli console warning # Filter by level
233
- patchright-cli network # Network request log
297
+ patchright-cli console --clear # Clear after printing
234
298
  ```
235
299
 
236
300
  ### Sessions
@@ -242,8 +306,13 @@ patchright-cli list # List all sessions
242
306
  patchright-cli close-all
243
307
  patchright-cli kill-all
244
308
  patchright-cli delete-data # Delete persistent profile
309
+ patchright-cli --port=9322 open # Custom daemon port
245
310
  ```
246
311
 
312
+ </details>
313
+
314
+ ---
315
+
247
316
  ## Snapshots
248
317
 
249
318
  After each state-changing command, the CLI outputs page info and a YAML snapshot:
@@ -256,7 +325,7 @@ After each state-changing command, the CLI outputs page info and a YAML snapshot
256
325
  [Snapshot](.patchright-cli/page-1774376207818.yml)
257
326
  ```
258
327
 
259
- The snapshot lists interactive elements with refs:
328
+ The snapshot lists interactive elements with refs you can use in commands:
260
329
 
261
330
  ```yaml
262
331
  - ref: e1
@@ -269,32 +338,44 @@ The snapshot lists interactive elements with refs:
269
338
  url: "https://iana.org/domains/example"
270
339
  ```
271
340
 
272
- Use refs in commands: `patchright-cli click e2`, `patchright-cli fill e5 "text"`.
341
+ > [!NOTE]
342
+ > Use refs directly: `patchright-cli click e2`, `patchright-cli fill e5 "text"`
343
+
344
+ ---
273
345
 
274
346
  ## Anti-Detect Features
275
347
 
276
- - Real Chrome browser (not Chromium)
277
- - Patchright patches `navigator.webdriver` and other detection vectors
278
- - Persistent profiles maintain cookies/sessions across runs
279
- - No custom user-agent or headers (natural fingerprint)
280
- - Headed by default (headless is more detectable)
348
+ > [!CAUTION]
349
+ > This tool is for **authorized testing, security research, and legitimate automation** only.
281
350
 
282
- ## Claude Code Integration
351
+ - :white_check_mark: Real Chrome browser (not Chromium)
352
+ - :white_check_mark: Patchright patches `navigator.webdriver` and other detection vectors
353
+ - :white_check_mark: Persistent profiles maintain cookies/sessions across runs
354
+ - :white_check_mark: No custom user-agent or headers (natural fingerprint)
355
+ - :white_check_mark: Headed by default (headless is more detectable)
283
356
 
284
- Add the skill to your project:
357
+ ---
285
358
 
286
- ```bash
287
- cp -r skills/patchright-cli ~/.claude/skills/
288
- ```
359
+ ## Agent Integration
289
360
 
290
- Then use in Claude Code:
291
- ```
292
- patchright-cli open https://protected-site.com
293
- patchright-cli snapshot
294
- patchright-cli fill e3 "username"
295
- patchright-cli fill e4 "password"
296
- patchright-cli click e5
297
- ```
361
+ Works with any AI coding agent that supports SKILL.md skills:
362
+
363
+ | Agent | Install skill |
364
+ |-------|--------------|
365
+ | **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` |
366
+ | **OpenClaw** | `mkdir -p ~/.openclaw/skills/patchright-cli && curl -sL https://raw.githubusercontent.com/AhaiMk01/patchright-cli/main/skills/patchright-cli/SKILL.md -o ~/.openclaw/skills/patchright-cli/SKILL.md` |
367
+ | **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` |
368
+ | **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` |
369
+ | **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` |
370
+ | **Cursor** | Copy SKILL.md to `.cursor/skills/patchright-cli/` in your project |
371
+ | **Windsurf** | Copy SKILL.md to `.windsurf/skills/patchright-cli/` in your project |
372
+ | **Aider** | Copy SKILL.md to `.aider/skills/patchright-cli/` in your project |
373
+
374
+ Or just tell your agent:
375
+
376
+ > Install patchright-cli skill from https://raw.githubusercontent.com/AhaiMk01/patchright-cli/main/skills/patchright-cli/SKILL.md
377
+
378
+ ---
298
379
 
299
380
  ## Star History
300
381
 
@@ -306,6 +387,34 @@ patchright-cli click e5
306
387
  </picture>
307
388
  </a>
308
389
 
390
+ ---
391
+
392
+ <details>
393
+ <summary><h2>Differences from playwright-cli</h2></summary>
394
+
395
+ patchright-cli aims for full command parity with [Microsoft's playwright-cli](https://github.com/microsoft/playwright-cli). The following playwright-cli features are **intentionally not implemented** due to Patchright's architecture:
396
+
397
+ | Feature | Reason |
398
+ |---------|--------|
399
+ | `--browser=firefox/webkit/msedge` | Patchright only supports Chromium/Chrome. Anti-detect patches are Chrome-specific. |
400
+ | `--config=<file>` | No config file system. Options are passed as CLI flags. |
401
+ | `--extension` | Browser extension connection not supported. Patchright uses CDP directly. |
402
+ | `show` / `devtools-start` | DevTools are available natively in headed mode (default). |
403
+ | `install` / `install-browser` | Use `python -m patchright install chromium` instead. |
404
+
405
+ All other commands and options are fully supported.
406
+
407
+ </details>
408
+
409
+ ---
410
+
411
+ ## Disclaimer
412
+
413
+ > [!WARNING]
414
+ > This tool is provided for **authorized security testing, legitimate automation, and educational purposes** only. Users are solely responsible for ensuring their use complies with applicable laws and the terms of service of any websites they interact with. The authors do not endorse or encourage any unauthorized access, scraping, or circumvention of security measures. Use at your own risk.
415
+
416
+ ---
417
+
309
418
  ## License
310
419
 
311
420
  Apache 2.0 — same as [playwright-cli](https://github.com/microsoft/playwright-cli)