playwright-repl 0.2.1 → 0.7.10

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/README.md DELETED
@@ -1,418 +0,0 @@
1
- # playwright-repl
2
-
3
- ![playwright-repl](cover-image.png)
4
-
5
- Interactive REPL for Playwright browser automation — keyword-driven testing from your terminal.
6
-
7
- Inspired by [playwright-cli](https://github.com/anthropics/playwright-cli), reusing its command vocabulary and Playwright MCP daemon. Where playwright-cli is designed for AI agents (one command per process), playwright-repl is designed for **humans** — a persistent session with recording, replay, and instant feedback.
8
-
9
- ## Why?
10
-
11
- The `playwright-cli` tool spawns a new Node.js process **per command** — connecting to the daemon, sending one message, and exiting. That's ~50–100ms overhead each time.
12
-
13
- **playwright-repl** keeps a persistent socket connection open. Type a command, see the result instantly. Record your session, replay it later — no code, no tokens, no setup.
14
-
15
- Key features beyond playwright-cli:
16
- - **Text locators** — use `click "Submit"` or `fill "Email" "test@example.com"` instead of element refs. Auto-resolves via getByText, getByLabel, getByPlaceholder, and getByRole with fallback chains
17
- - **Element refs** — also supports ref-based commands (`click e5`, `fill e7 "hello"`) from `snapshot` output
18
- - **Assertions** — `verify-text`, `verify-element`, `verify-value`, `verify-list` for inline validation
19
- - **Record & replay** — capture sessions as `.pw` files and replay them headlessly or step-by-step
20
-
21
- ```
22
- pw> goto https://demo.playwright.dev/todomvc/
23
- pw> fill "What needs to be done?" "Buy groceries"
24
- pw> press Enter
25
- pw> fill "What needs to be done?" "Write tests"
26
- pw> press Enter
27
- pw> check "Buy groceries"
28
- pw> verify-text "1 item left"
29
- ```
30
-
31
- Record it, replay it later:
32
-
33
- ```bash
34
- pw> .record smoke-test
35
- ⏺ Recording to smoke-test.pw
36
-
37
- pw> goto https://demo.playwright.dev/todomvc/
38
- pw> fill "What needs to be done?" "Buy groceries"
39
- pw> press Enter
40
- pw> verify-text "1 item left"
41
- pw> .save
42
- ✓ Saved 4 commands to smoke-test.pw
43
-
44
- # Replay any time
45
- $ playwright-repl --replay smoke-test.pw
46
- ```
47
-
48
- ## Install
49
-
50
- ```bash
51
- npm install -g playwright-repl
52
-
53
- # If you don't have browser binaries yet
54
- npx playwright install
55
-
56
- # Or install from source
57
- git clone https://github.com/stevez/playwright-repl.git
58
- cd playwright-repl && npm install && npm link
59
- ```
60
-
61
- ## Quick Start
62
-
63
- ```bash
64
- # Start the REPL (launches browser automatically)
65
- playwright-repl
66
-
67
- # With a visible browser
68
- playwright-repl --headed
69
-
70
- # With a specific browser
71
- playwright-repl --headed --browser firefox
72
- ```
73
-
74
- Once inside the REPL, use either **text locators** or **element refs**:
75
-
76
- ```
77
- pw> goto https://demo.playwright.dev/todomvc/
78
-
79
- # Text locators — no snapshot needed
80
- pw> fill "What needs to be done?" "Buy groceries"
81
- pw> press Enter
82
- pw> check "Buy groceries"
83
- pw> verify-text "0 items left"
84
-
85
- # Or use element refs from snapshot
86
- pw> snapshot
87
- - textbox "What needs to be done?" [ref=e8]
88
- - listitem "Buy groceries" [ref=e21]
89
-
90
- pw> click e21 # click by ref
91
- pw> screenshot # take a screenshot
92
- pw> close # close browser
93
- ```
94
-
95
- ## Usage
96
-
97
- ```bash
98
- # Interactive REPL
99
- playwright-repl [options]
100
-
101
- # Replay a recorded session
102
- playwright-repl --replay session.pw
103
-
104
- # Step through replay (pause between commands)
105
- playwright-repl --replay session.pw --step
106
-
107
- # Start REPL with recording enabled
108
- playwright-repl --record my-test.pw
109
-
110
- # Pipe commands
111
- echo -e "goto https://example.com\nsnapshot" | playwright-repl
112
-
113
- # Named sessions
114
- playwright-repl --session checkout-flow --headed
115
- ```
116
-
117
- ### CLI Options
118
-
119
- | Option | Description |
120
- |--------|-------------|
121
- | `-s, --session <name>` | Session name (default: `"default"`) |
122
- | `-b, --browser <type>` | Browser: `chrome`, `firefox`, `webkit`, `msedge` |
123
- | `--headed` | Run browser in headed (visible) mode |
124
- | `--persistent` | Use persistent browser profile |
125
- | `--profile <dir>` | Persistent profile directory |
126
- | `--config <file>` | Path to config file |
127
- | `--replay <file>` | Replay a `.pw` session file |
128
- | `--record <file>` | Start REPL with recording to file |
129
- | `--step` | Pause between commands during replay |
130
- | `-q, --silent` | Suppress banner and status messages |
131
- | `-h, --help` | Show help |
132
-
133
- ## MCP Server
134
-
135
- `playwright-repl` also ships an MCP server that exposes Playwright's full browser automation toolkit to AI agents (Claude, Cursor, etc.) over stdio.
136
-
137
- ```bash
138
- # Run directly
139
- npx -p playwright-repl playwright-mcp-server
140
-
141
- # With visible browser
142
- npx -p playwright-repl playwright-mcp-server --headed
143
- ```
144
-
145
- ### VS Code / Cursor Configuration
146
-
147
- Add to `.vscode/mcp.json` in your project:
148
-
149
- ```json
150
- {
151
- "servers": {
152
- "playwright": {
153
- "command": "npx",
154
- "args": ["-p", "playwright-repl", "playwright-mcp-server"]
155
- }
156
- }
157
- }
158
- ```
159
-
160
- Or with a visible browser:
161
-
162
- ```json
163
- {
164
- "servers": {
165
- "playwright": {
166
- "command": "npx",
167
- "args": ["-p", "playwright-repl", "playwright-mcp-server", "--headed"]
168
- }
169
- }
170
- }
171
- ```
172
-
173
- ### MCP Server Options
174
-
175
- | Option | Description |
176
- |--------|-------------|
177
- | `--headed` | Run browser in headed (visible) mode |
178
-
179
- ## Commands
180
-
181
- ### Navigation
182
-
183
- | Command | Alias | Description |
184
- |---------|-------|-------------|
185
- | `goto <url>` | `g` | Navigate to a URL |
186
- | `open [url]` | `o` | Open browser (optionally navigate) |
187
- | `go-back` | `back` | Go back in history |
188
- | `go-forward` | `fwd` | Go forward in history |
189
- | `reload` | `r` | Reload page |
190
-
191
- ### Interaction
192
-
193
- | Command | Alias | Description |
194
- |---------|-------|-------------|
195
- | `click <ref>` | `c` | Click an element |
196
- | `dblclick <ref>` | `dc` | Double-click an element |
197
- | `fill <ref> <text>` | `f` | Fill a form field |
198
- | `type <text>` | `t` | Type text key by key |
199
- | `press <key>` | `p` | Press a keyboard key |
200
- | `hover <ref>` | `h` | Hover over element |
201
- | `select <ref> <value>` | `sel` | Select dropdown option |
202
- | `check <ref>` | `chk` | Check a checkbox |
203
- | `uncheck <ref>` | `unchk` | Uncheck a checkbox |
204
- | `upload <ref> <file>` | — | Upload a file |
205
- | `drag <from> <to>` | — | Drag and drop |
206
-
207
- ### Inspection
208
-
209
- | Command | Alias | Description |
210
- |---------|-------|-------------|
211
- | `snapshot` | `s` | Accessibility tree with element refs |
212
- | `screenshot` | `ss` | Take a screenshot |
213
- | `eval <expr>` | `e` | Evaluate JavaScript |
214
- | `console` | `con` | Browser console messages |
215
- | `network` | `net` | Network requests log |
216
- | `run-code <code>` | — | Run Playwright code directly |
217
-
218
- ### Assertions
219
-
220
- | Command | Alias | Description |
221
- |---------|-------|-------------|
222
- | `verify-text <text>` | `vt` | Verify text is visible on page |
223
- | `verify-element <role> <name>` | `ve` | Verify element exists by role and name |
224
- | `verify-value <ref> <value>` | `vv` | Verify input/select/checkbox value |
225
- | `verify-list <ref> <items>` | `vl` | Verify list contains expected items |
226
-
227
- ### Tabs
228
-
229
- | Command | Alias | Description |
230
- |---------|-------|-------------|
231
- | `tab-list` | `tl` | List open tabs |
232
- | `tab-new [url]` | `tn` | Open a new tab |
233
- | `tab-close [index]` | `tc` | Close a tab |
234
- | `tab-select <index>` | `ts` | Switch to a tab |
235
-
236
- ### Storage & Cookies
237
-
238
- | Command | Description |
239
- |---------|-------------|
240
- | `state-save [file]` | Save auth state (cookies + storage) |
241
- | `state-load <file>` | Load auth state |
242
- | `cookie-list` | List all cookies |
243
- | `cookie-get <name>` | Get a specific cookie |
244
- | `cookie-set <name> <value>` | Set a cookie |
245
- | `cookie-delete <name>` | Delete a cookie |
246
- | `cookie-clear` | Clear all cookies |
247
- | `localstorage-list` | List all localStorage |
248
- | `localstorage-get <key>` | Get localStorage value |
249
- | `localstorage-set <key> <value>` | Set localStorage value |
250
- | `localstorage-delete <key>` | Delete localStorage key |
251
- | `localstorage-clear` | Clear all localStorage |
252
- | `sessionstorage-list` | List all sessionStorage |
253
- | `sessionstorage-get <key>` | Get sessionStorage value |
254
- | `sessionstorage-set <key> <value>` | Set sessionStorage value |
255
- | `sessionstorage-delete <key>` | Delete sessionStorage key |
256
- | `sessionstorage-clear` | Clear all sessionStorage |
257
-
258
- ### Network Routing
259
-
260
- | Command | Description |
261
- |---------|-------------|
262
- | `route <pattern>` | Intercept network requests |
263
- | `route-list` | List active routes |
264
- | `unroute [pattern]` | Remove route(s) |
265
-
266
- ### Dialogs & Layout
267
-
268
- | Command | Description |
269
- |---------|-------------|
270
- | `dialog-accept [text]` | Accept a browser dialog |
271
- | `dialog-dismiss` | Dismiss a browser dialog |
272
- | `resize <w> <h>` | Resize browser window |
273
- | `pdf` | Save page as PDF |
274
-
275
- ### Session Management
276
-
277
- | Command | Alias | Description |
278
- |---------|-------|-------------|
279
- | `list` | `ls` | List active sessions |
280
- | `close` | `q` | Close the browser |
281
- | `close-all` | — | Close all sessions |
282
- | `kill-all` | — | Kill all daemon processes |
283
- | `config-print` | — | Print daemon config |
284
- | `install-browser` | — | Install browser binaries |
285
-
286
- ### REPL Meta-Commands
287
-
288
- | Command | Description |
289
- |---------|-------------|
290
- | `.help` | Show available commands |
291
- | `.aliases` | Show all command aliases |
292
- | `.status` | Show connection status |
293
- | `.reconnect` | Reconnect to daemon |
294
- | `.record [file]` | Start recording commands |
295
- | `.save` | Stop recording and save to file |
296
- | `.pause` | Pause/resume recording |
297
- | `.discard` | Discard current recording |
298
- | `.replay <file>` | Replay a recorded session |
299
- | `.exit` | Exit REPL (also Ctrl+D) |
300
-
301
- ## Session Recording & Replay
302
-
303
- Record your browser interactions and replay them later — great for regression tests, onboarding demos, or sharing reproducible flows.
304
-
305
- ### Record
306
-
307
- ```bash
308
- # From CLI
309
- playwright-repl --record my-test.pw --headed
310
-
311
- # Or inside the REPL
312
- pw> .record my-test
313
- ⏺ Recording to my-test.pw
314
- pw> goto https://demo.playwright.dev/todomvc/
315
- pw> fill "What needs to be done?" "Buy groceries"
316
- pw> press Enter
317
- pw> verify-text "1 item left"
318
- pw> .save
319
- ✓ Saved 4 commands to my-test.pw
320
- ```
321
-
322
- ### Replay
323
-
324
- ```bash
325
- # Full speed
326
- playwright-repl --replay my-test.pw
327
-
328
- # Step-through (press Enter between commands)
329
- playwright-repl --replay my-test.pw --step --headed
330
-
331
- # Or inside the REPL
332
- pw> .replay my-test.pw
333
- ```
334
-
335
- ### File Format
336
-
337
- `.pw` files are plain text — human-readable, diffable, version-controllable:
338
-
339
- ```
340
- # CI smoke test — quick add-and-verify
341
- # App: https://demo.playwright.dev/todomvc/
342
-
343
- goto https://demo.playwright.dev/todomvc/
344
- fill "What needs to be done?" "Buy groceries"
345
- press Enter
346
- verify-text "Buy groceries"
347
- verify-text "1 item left"
348
- ```
349
-
350
- ### Recording Controls
351
-
352
- | Command | Description |
353
- |---------|-------------|
354
- | `.record [file]` | Start recording |
355
- | `.pause` | Pause recording (toggle) |
356
- | `.save` | Stop and save to file |
357
- | `.discard` | Discard without saving |
358
-
359
- ## Examples
360
-
361
- All examples use the [TodoMVC demo](https://demo.playwright.dev/todomvc/) and can be run directly:
362
-
363
- | File | Description |
364
- |------|-------------|
365
- | [01-add-todos.pw](examples/01-add-todos.pw) | Add todos and verify with assertions |
366
- | [02-complete-and-filter.pw](examples/02-complete-and-filter.pw) | Complete todos, use filters |
367
- | [03-record-session.pw](examples/03-record-session.pw) | Record a test session |
368
- | [04-replay-session.pw](examples/04-replay-session.pw) | Replay with step-through |
369
- | [05-ci-pipe.pw](examples/05-ci-pipe.pw) | CI smoke test |
370
- | [06-edit-todo.pw](examples/06-edit-todo.pw) | Double-click to edit a todo |
371
-
372
- Try one:
373
-
374
- ```bash
375
- # Run an example with a visible browser
376
- playwright-repl --replay examples/01-add-todos.pw --headed
377
-
378
- # Step through an example interactively
379
- playwright-repl --replay examples/04-replay-session.pw --step --headed
380
-
381
- # Run as a CI smoke test (headless, silent)
382
- playwright-repl --replay examples/05-ci-pipe.pw --silent
383
- ```
384
-
385
- ## Architecture
386
-
387
- ![Architecture](architecture-diagram.png)
388
-
389
- The REPL replaces only the **client half** of playwright-cli. The daemon, browser, and all tool handlers are unchanged — both CLI and REPL produce identical wire messages.
390
-
391
- ### How It Works
392
-
393
- 1. **Startup**: The REPL starts the Playwright daemon (if not already running) and connects via Unix socket / Windows named pipe
394
- 2. **Input**: User types a command like `click e5`
395
- 3. **Parse**: Alias resolution (`c` → `click`) + minimist parsing → `{ _: ["click", "e5"] }`
396
- 4. **Send**: JSON message over socket to the daemon
397
- 5. **Execute**: Daemon maps the command to a Playwright API call and executes it
398
- 6. **Result**: Response rendered in the terminal
399
-
400
- ### Socket Path
401
-
402
- The daemon socket includes a hash of the workspace directory:
403
-
404
- ```
405
- Linux/macOS: /tmp/playwright-cli/{hash}/{session}.sock
406
- Windows: \\.\pipe\{hash}-{session}.sock
407
- ```
408
-
409
- Both REPL and daemon hash the same `package.json` path, so they always find each other.
410
-
411
- ## Requirements
412
-
413
- - **Node.js** >= 18
414
- - **playwright** >= 1.59.0-alpha (includes `lib/mcp/terminal/` daemon)
415
-
416
- ## License
417
-
418
- MIT
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * Daemon launcher — replaces @playwright/cli entirely.
5
- * Same pattern, pointing to our own package.json for the socket hash.
6
- */
7
-
8
- const { program } = require('playwright/lib/mcp/terminal/program');
9
- const packageLocation = require.resolve('../package.json');
10
- program(packageLocation).catch(e => {
11
- console.error(e.message);
12
- process.exit(1);
13
- });
@@ -1,32 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * Thin MCP server entrypoint — uses Playwright's built-in MCP infrastructure.
5
- * Starts a stdio MCP server with all browser tools available.
6
- *
7
- * Uses only publicly exported paths:
8
- * - playwright/lib/mcp/index → createConnection()
9
- * - playwright-core/lib/mcpBundle → StdioServerTransport
10
- */
11
-
12
- const { createConnection } = require('playwright/lib/mcp/index');
13
- const { StdioServerTransport } = require('playwright-core/lib/mcpBundle');
14
-
15
- // ─── Parse CLI args ───
16
-
17
- const args = process.argv.slice(2);
18
- const headed = args.includes('--headed');
19
-
20
- (async () => {
21
- const server = await createConnection({
22
- browser: {
23
- launchOptions: { headless: !headed },
24
- },
25
- });
26
-
27
- const transport = new StdioServerTransport();
28
- await server.connect(transport);
29
- })().catch(e => {
30
- console.error(e.message);
31
- process.exit(1);
32
- });
@@ -1,79 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * playwright-repl CLI entry point.
5
- *
6
- * Usage:
7
- * playwright-repl [options]
8
- * playwright-repl --replay session.pw
9
- * playwright-repl --replay session.pw --step
10
- * playwright-repl --record my-test.pw
11
- */
12
-
13
- import { minimist } from '../src/resolve.mjs';
14
- import { startRepl } from '../src/repl.mjs';
15
-
16
- const args = minimist(process.argv.slice(2), {
17
- boolean: ['headed', 'persistent', 'extension', 'help', 'step', 'silent'],
18
- string: ['session', 'browser', 'profile', 'config', 'replay', 'record'],
19
- alias: { s: 'session', h: 'help', b: 'browser', q: 'silent' },
20
- default: { session: 'default' },
21
- });
22
-
23
- if (args.help) {
24
- console.log(`
25
- playwright-repl - Interactive REPL for Playwright browser automation
26
-
27
- Usage:
28
- playwright-repl [options]
29
-
30
- Options:
31
- -s, --session <name> Session name (default: "default")
32
- -b, --browser <type> Browser: chrome, firefox, webkit, msedge
33
- --headed Run browser in headed mode
34
- --persistent Use persistent browser profile
35
- --profile <dir> Persistent profile directory
36
- --config <file> Path to config file
37
- --replay <file> Replay a .pw session file
38
- --record <file> Start REPL with recording to file
39
- --step Pause between commands during replay
40
- -q, --silent Suppress banner and status messages
41
- -h, --help Show this help
42
-
43
- REPL Meta-Commands:
44
- .help Show available commands
45
- .aliases Show command aliases
46
- .status Show connection status
47
- .reconnect Reconnect to daemon
48
- .record [filename] Start recording commands
49
- .save Stop recording and save to file
50
- .pause Pause/resume recording
51
- .discard Discard current recording
52
- .replay <filename> Replay a recorded session
53
- .exit / Ctrl+D Exit REPL
54
-
55
- Examples:
56
- playwright-repl # start REPL
57
- playwright-repl --headed # start with visible browser
58
- playwright-repl --replay login.pw # replay a session
59
- playwright-repl --replay login.pw --step # step through replay
60
- echo "open https://example.com" | playwright-repl # pipe commands
61
- `);
62
- process.exit(0);
63
- }
64
-
65
- startRepl({
66
- session: args.session,
67
- headed: args.headed,
68
- browser: args.browser,
69
- persistent: args.persistent,
70
- profile: args.profile,
71
- config: args.config,
72
- replay: args.replay,
73
- record: args.record,
74
- step: args.step,
75
- silent: args.silent,
76
- }).catch((err) => {
77
- console.error(`Fatal: ${err.message}`);
78
- process.exit(1);
79
- });
@@ -1,14 +0,0 @@
1
- # Add todos and verify they appear
2
- # App: https://demo.playwright.dev/todomvc/
3
-
4
- goto https://demo.playwright.dev/todomvc/
5
- fill "What needs to be done?" "Buy groceries"
6
- press Enter
7
- fill "What needs to be done?" "Write tests"
8
- press Enter
9
- fill "What needs to be done?" "Deploy to production"
10
- press Enter
11
- verify-text "Buy groceries"
12
- verify-text "Write tests"
13
- verify-text "Deploy to production"
14
- verify-text "3 items left"
@@ -1,21 +0,0 @@
1
- # Complete a todo and use filters
2
- # App: https://demo.playwright.dev/todomvc/
3
-
4
- goto https://demo.playwright.dev/todomvc/
5
- fill "What needs to be done?" "Buy groceries"
6
- press Enter
7
- fill "What needs to be done?" "Write tests"
8
- press Enter
9
- fill "What needs to be done?" "Deploy to production"
10
- press Enter
11
- check "Buy groceries"
12
- verify-text "2 items left"
13
- click "Active"
14
- verify-text "Write tests"
15
- verify-text "Deploy to production"
16
- click "Completed"
17
- verify-text "Buy groceries"
18
- click "All"
19
- click "Clear completed"
20
- verify-text "Write tests"
21
- verify-text "Deploy to production"
@@ -1,13 +0,0 @@
1
- # Record and save a smoke test
2
- # App: https://demo.playwright.dev/todomvc/
3
- # Usage: playwright-repl --replay examples/03-record-session.pw --headed
4
-
5
- goto https://demo.playwright.dev/todomvc/
6
- fill "What needs to be done?" "Buy groceries"
7
- press Enter
8
- fill "What needs to be done?" "Write tests"
9
- press Enter
10
- check "Buy groceries"
11
- verify-text "1 item left"
12
- click "Clear completed"
13
- verify-text "Write tests"
@@ -1,17 +0,0 @@
1
- # Replay demo — add todos, complete them, verify count
2
- # App: https://demo.playwright.dev/todomvc/
3
- # Full speed: playwright-repl --replay examples/04-replay-session.pw
4
- # Step-through: playwright-repl --replay examples/04-replay-session.pw --step --headed
5
-
6
- goto https://demo.playwright.dev/todomvc/
7
- fill "What needs to be done?" "Buy groceries"
8
- press Enter
9
- fill "What needs to be done?" "Write tests"
10
- press Enter
11
- fill "What needs to be done?" "Deploy to production"
12
- press Enter
13
- verify-text "3 items left"
14
- check "Buy groceries"
15
- verify-text "2 items left"
16
- check "Write tests"
17
- verify-text "1 item left"
@@ -1,14 +0,0 @@
1
- # CI smoke test — quick add-and-verify
2
- # App: https://demo.playwright.dev/todomvc/
3
- # Usage: playwright-repl --replay examples/05-ci-pipe.pw --silent
4
-
5
- goto https://demo.playwright.dev/todomvc/
6
- fill "What needs to be done?" "Buy groceries"
7
- press Enter
8
- verify-text "Buy groceries"
9
- verify-text "1 item left"
10
- fill "What needs to be done?" "Write tests"
11
- press Enter
12
- verify-text "2 items left"
13
- check "Buy groceries"
14
- verify-text "1 item left"
@@ -1,11 +0,0 @@
1
- # Double-click to edit a todo
2
- # App: https://demo.playwright.dev/todomvc/
3
-
4
- goto https://demo.playwright.dev/todomvc/
5
- fill "What needs to be done?" "Buy groceries"
6
- press Enter
7
- dblclick "Buy groceries"
8
- press Control+a
9
- type "Buy organic groceries"
10
- press Enter
11
- verify-text "Buy organic groceries"