@guanzhu.me/pw-cli 0.0.1
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.
- package/LICENSE +21 -0
- package/README.md +333 -0
- package/bin/pw-cli.js +870 -0
- package/package.json +38 -0
- package/src/browser-manager.js +178 -0
- package/src/cli.js +168 -0
- package/src/executor.js +77 -0
- package/src/launch-daemon.js +65 -0
- package/src/queue.js +48 -0
- package/src/state.js +47 -0
- package/src/utils.js +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
# pw-cli
|
|
2
|
+
|
|
3
|
+
`pw-cli` is a small Node.js CLI that keeps a Playwright browser session alive and makes repeat browser automation commands faster to run.
|
|
4
|
+
|
|
5
|
+
It is designed for a local, interactive workflow:
|
|
6
|
+
|
|
7
|
+
- Default to headed mode instead of headless
|
|
8
|
+
- Reuse a persistent browser/profile between commands
|
|
9
|
+
- Run inline code or `.js` scripts against the active page
|
|
10
|
+
- Queue multiple actions and execute them in order
|
|
11
|
+
- Add convenience behavior around Playwright CLI sessions and XPath-based commands
|
|
12
|
+
|
|
13
|
+
## Why this project exists
|
|
14
|
+
|
|
15
|
+
Raw Playwright is excellent for test suites and scripted automation, but ad hoc browser control from the terminal is often slower than it needs to be. `pw-cli` optimizes for that interactive loop by reusing a browser session and exposing a CLI-first interface.
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
|
|
19
|
+
- Persistent Chromium session reuse
|
|
20
|
+
- Headed mode by default
|
|
21
|
+
- Named profile support
|
|
22
|
+
- `run-code` for inline JavaScript or piped stdin
|
|
23
|
+
- `run-script` for executing local JavaScript files
|
|
24
|
+
- Queue management for multi-step flows
|
|
25
|
+
- Automatic browser launch when needed
|
|
26
|
+
- XPath command conversion for common actions
|
|
27
|
+
|
|
28
|
+
## Requirements
|
|
29
|
+
|
|
30
|
+
- Node.js 18+
|
|
31
|
+
- `playwright`
|
|
32
|
+
- `@playwright/cli`
|
|
33
|
+
|
|
34
|
+
`pw-cli` declares Playwright packages as peer dependencies because many users already have them installed globally or inside their automation environment.
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
Install the package itself:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm install -g @guanzhu.me/pw-cli
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Install the required Playwright packages if they are not already available:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm install -g playwright @playwright/cli
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Quick start
|
|
51
|
+
|
|
52
|
+
Open a page:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pw-cli open https://example.com
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Run inline automation:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
pw-cli run-code "await page.goto('https://example.com'); return await page.title()"
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Pipe code from stdin:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
echo "return await page.url()" | pw-cli run-code
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Run a local script:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pw-cli run-script ./scrape.js --url https://example.com
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Use XPath with common commands:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
pw-cli click "//button[contains(., 'Submit')]"
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Use the queue:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
pw-cli queue add goto https://example.com
|
|
86
|
+
pw-cli queue add snapshot
|
|
87
|
+
pw-cli queue run
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Inspect browser sessions:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
pw-cli list
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## How pw-cli differs from playwright-cli
|
|
97
|
+
|
|
98
|
+
`pw-cli` keeps the `playwright-cli` command model and command grouping, but adds a few workflow-oriented behaviors:
|
|
99
|
+
|
|
100
|
+
- `open` injects headed and persistent defaults
|
|
101
|
+
- Browser-backed commands can auto-open a browser session if needed
|
|
102
|
+
- `run-code` accepts stdin and plain inline statements
|
|
103
|
+
- `run-script` executes a local `.js` file with Playwright globals
|
|
104
|
+
- Common element commands accept XPath refs
|
|
105
|
+
- `queue` lets you batch multiple commands and run them in order
|
|
106
|
+
|
|
107
|
+
## Command reference
|
|
108
|
+
|
|
109
|
+
The structure below intentionally follows `playwright-cli`, with `pw-cli` differences called out inline.
|
|
110
|
+
|
|
111
|
+
### Usage
|
|
112
|
+
|
|
113
|
+
```text
|
|
114
|
+
pw-cli <command> [args] [options]
|
|
115
|
+
pw-cli -s=<session> <command> [args] [options]
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Core
|
|
119
|
+
|
|
120
|
+
```text
|
|
121
|
+
open [url] open the browser
|
|
122
|
+
pw-cli: injects headed + persistent defaults
|
|
123
|
+
pw-cli: if url is provided, opens first and then navigates
|
|
124
|
+
close close the browser
|
|
125
|
+
goto <url> navigate to a url
|
|
126
|
+
type <text> type text into editable element
|
|
127
|
+
click <ref> [button] perform click on a web page
|
|
128
|
+
pw-cli: accepts XPath ref
|
|
129
|
+
dblclick <ref> [button] perform double click on a web page
|
|
130
|
+
pw-cli: accepts XPath ref
|
|
131
|
+
fill <ref> <text> fill text into editable element
|
|
132
|
+
pw-cli: accepts XPath ref
|
|
133
|
+
drag <startRef> <endRef> perform drag and drop between two elements
|
|
134
|
+
pw-cli: accepts XPath refs
|
|
135
|
+
hover <ref> hover over element on page
|
|
136
|
+
pw-cli: accepts XPath ref
|
|
137
|
+
select <ref> <val> select an option in a dropdown
|
|
138
|
+
pw-cli: accepts XPath ref
|
|
139
|
+
upload <file> upload one or multiple files
|
|
140
|
+
check <ref> check a checkbox or radio button
|
|
141
|
+
pw-cli: accepts XPath ref
|
|
142
|
+
uncheck <ref> uncheck a checkbox or radio button
|
|
143
|
+
pw-cli: accepts XPath ref
|
|
144
|
+
snapshot capture page snapshot to obtain element ref
|
|
145
|
+
eval <func> [ref] evaluate javascript expression on page or element
|
|
146
|
+
dialog-accept [prompt] accept a dialog
|
|
147
|
+
dialog-dismiss dismiss a dialog
|
|
148
|
+
resize <w> <h> resize the browser window
|
|
149
|
+
delete-data delete session data
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Navigation
|
|
153
|
+
|
|
154
|
+
```text
|
|
155
|
+
go-back go back to the previous page
|
|
156
|
+
go-forward go forward to the next page
|
|
157
|
+
reload reload the current page
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Keyboard
|
|
161
|
+
|
|
162
|
+
```text
|
|
163
|
+
press <key> press a key on the keyboard, `a`, `arrowleft`
|
|
164
|
+
keydown <key> press a key down on the keyboard
|
|
165
|
+
keyup <key> press a key up on the keyboard
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Mouse
|
|
169
|
+
|
|
170
|
+
```text
|
|
171
|
+
mousemove <x> <y> move mouse to a given position
|
|
172
|
+
mousedown [button] press mouse down
|
|
173
|
+
mouseup [button] press mouse up
|
|
174
|
+
mousewheel <dx> <dy> scroll mouse wheel
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Save as
|
|
178
|
+
|
|
179
|
+
```text
|
|
180
|
+
screenshot [ref] screenshot of the current page or element
|
|
181
|
+
pdf save page as pdf
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Tabs
|
|
185
|
+
|
|
186
|
+
```text
|
|
187
|
+
tab-list list all tabs
|
|
188
|
+
tab-new [url] create a new tab
|
|
189
|
+
tab-close [index] close a browser tab
|
|
190
|
+
tab-select <index> select a browser tab
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Storage
|
|
194
|
+
|
|
195
|
+
```text
|
|
196
|
+
state-load <filename> loads browser storage (authentication) state from a file
|
|
197
|
+
state-save [filename] saves the current storage (authentication) state to a file
|
|
198
|
+
cookie-list list all cookies (optionally filtered by domain/path)
|
|
199
|
+
cookie-get <name> get a specific cookie by name
|
|
200
|
+
cookie-set <name> <value> set a cookie with optional flags
|
|
201
|
+
cookie-delete <name> delete a specific cookie
|
|
202
|
+
cookie-clear clear all cookies
|
|
203
|
+
localstorage-list list all localstorage key-value pairs
|
|
204
|
+
localstorage-get <key> get a localstorage item by key
|
|
205
|
+
localstorage-set <key> <value> set a localstorage item
|
|
206
|
+
localstorage-delete <key> delete a localstorage item
|
|
207
|
+
localstorage-clear clear all localstorage
|
|
208
|
+
sessionstorage-list list all sessionstorage key-value pairs
|
|
209
|
+
sessionstorage-get <key> get a sessionstorage item by key
|
|
210
|
+
sessionstorage-set <key> <value> set a sessionstorage item
|
|
211
|
+
sessionstorage-delete <key> delete a sessionstorage item
|
|
212
|
+
sessionstorage-clear clear all sessionstorage
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Network
|
|
216
|
+
|
|
217
|
+
```text
|
|
218
|
+
route <pattern> mock network requests matching a url pattern
|
|
219
|
+
route-list list all active network routes
|
|
220
|
+
unroute [pattern] remove routes matching a pattern (or all routes)
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### DevTools
|
|
224
|
+
|
|
225
|
+
```text
|
|
226
|
+
console [min-level] list console messages
|
|
227
|
+
run-code <code> run playwright code snippet
|
|
228
|
+
pw-cli: reads code from stdin when <code> is omitted
|
|
229
|
+
pw-cli: wraps plain statements in an async function
|
|
230
|
+
run-script <file> [...] run a local JavaScript file with page/context/browser globals
|
|
231
|
+
network list all network requests since loading the page
|
|
232
|
+
tracing-start start trace recording
|
|
233
|
+
tracing-stop stop trace recording
|
|
234
|
+
video-start start video recording
|
|
235
|
+
video-stop stop video recording
|
|
236
|
+
show show browser devtools
|
|
237
|
+
devtools-start show browser devtools
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### Install
|
|
241
|
+
|
|
242
|
+
```text
|
|
243
|
+
install initialize workspace
|
|
244
|
+
install-browser install browser
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Browser sessions
|
|
248
|
+
|
|
249
|
+
```text
|
|
250
|
+
list list browser sessions
|
|
251
|
+
close-all close all browser sessions
|
|
252
|
+
kill-all forcefully kill all browser sessions (for stale/zombie processes)
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### pw-cli queue
|
|
256
|
+
|
|
257
|
+
```text
|
|
258
|
+
queue add <command> [args...] add a command to the queue
|
|
259
|
+
queue list show queued commands
|
|
260
|
+
queue run [--fail-fast] execute queued commands in order
|
|
261
|
+
queue remove <id> remove a queued command by id prefix
|
|
262
|
+
queue clear clear the queue
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
Run `pw-cli queue help` for queue-specific help text.
|
|
266
|
+
|
|
267
|
+
### Global options
|
|
268
|
+
|
|
269
|
+
```text
|
|
270
|
+
--help [command] print help
|
|
271
|
+
-h print help
|
|
272
|
+
--version print version
|
|
273
|
+
-s, --session <name> choose browser session
|
|
274
|
+
--headless used by pw-cli-managed browser launches
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## Examples
|
|
278
|
+
|
|
279
|
+
```bash
|
|
280
|
+
pw-cli open https://example.com
|
|
281
|
+
pw-cli run-code "await page.goto('https://example.com'); return await page.title()"
|
|
282
|
+
echo "return await page.url()" | pw-cli run-code
|
|
283
|
+
pw-cli run-script ./scripts/smoke.js --env prod
|
|
284
|
+
pw-cli click "//button[contains(., 'Submit')]"
|
|
285
|
+
pw-cli queue add goto https://example.com
|
|
286
|
+
pw-cli queue add snapshot
|
|
287
|
+
pw-cli queue run
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
## Development
|
|
291
|
+
|
|
292
|
+
Clone the repository and install dependencies if you want local Playwright integration:
|
|
293
|
+
|
|
294
|
+
```bash
|
|
295
|
+
npm install
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
Run the validation suite:
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
npm run verify
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
Current automated checks focus on syntax and non-browser unit coverage. Browser-level integration testing can be added later once the public CLI contract is finalized.
|
|
305
|
+
|
|
306
|
+
## Project layout
|
|
307
|
+
|
|
308
|
+
```text
|
|
309
|
+
bin/ Executable entrypoint
|
|
310
|
+
src/ CLI logic, browser management, executor, queue, state helpers
|
|
311
|
+
examples/ Example assets
|
|
312
|
+
skills/ Internal skill/reference material used by the authoring workflow
|
|
313
|
+
test/ Node.js built-in test suite
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
## Roadmap
|
|
317
|
+
|
|
318
|
+
- Add integration tests for browser lifecycle and session reuse
|
|
319
|
+
- Publish versioned release notes
|
|
320
|
+
- Clarify compatibility with upstream Playwright CLI changes
|
|
321
|
+
- Add example scripts for common workflows
|
|
322
|
+
|
|
323
|
+
## Contributing
|
|
324
|
+
|
|
325
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md).
|
|
326
|
+
|
|
327
|
+
## Security
|
|
328
|
+
|
|
329
|
+
See [SECURITY.md](./SECURITY.md).
|
|
330
|
+
|
|
331
|
+
## License
|
|
332
|
+
|
|
333
|
+
MIT. See [LICENSE](./LICENSE).
|