playwright-repl 0.7.13 → 0.9.0

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 (2) hide show
  1. package/README.md +534 -0
  2. package/package.json +4 -3
package/README.md ADDED
@@ -0,0 +1,534 @@
1
+ # playwright-repl
2
+
3
+ ![playwright-repl](cover-image.png)
4
+
5
+ Interactive browser automation powered by Playwright — use it from your **terminal** or as a **Chrome side panel**.
6
+
7
+ Two frontends, one engine: the CLI gives you a terminal REPL with recording and replay; the Chrome extension gives you a DevTools panel with a script editor and visual recorder. Both run the same 55+ Playwright commands through a shared Engine — no command duplication.
8
+
9
+ ## Why?
10
+
11
+ **playwright-repl** runs Playwright's browser tools in-process. Type a command, see the result instantly. No code, no tokens, no setup.
12
+
13
+ - **CLI** — terminal REPL with recording, replay, piping, and 20+ aliases
14
+ - **Extension** — Chrome DevTools panel with script editor, recorder, and light/dark themes
15
+ - **Same commands everywhere** — `click`, `fill`, `snapshot`, `verify-text` work identically in both
16
+
17
+ Key features:
18
+ - **Text locators** — `click "Submit"` or `fill "Email" "test@example.com"` instead of element refs
19
+ - **Element refs** — `click e5`, `fill e7 "hello"` from `snapshot` output
20
+ - **Assertions** — `verify-text`, `verify-element`, `verify-value`, `verify-list`
21
+ - **Record & replay** — capture sessions as `.pw` files (CLI) or record interactions visually (extension)
22
+ - **Three connection modes** — launch a new browser, connect to existing Chrome, or use the extension relay
23
+
24
+ ## Architecture
25
+
26
+ The CLI and Extension use different execution paths.
27
+
28
+ **CLI** — commands execute in-process via the Engine:
29
+ ```
30
+ ┌──────────────┐
31
+ │ CLI (REPL) │
32
+ │ packages/cli│
33
+ └──────┬───────┘
34
+
35
+
36
+ ┌─────────────────┐
37
+ │ Engine │ (BrowserServerBackend in-process)
38
+ └──────┬──────────┘
39
+ │ CDP
40
+
41
+ ┌─────────────┐
42
+ │ Chrome │
43
+ └─────────────┘
44
+ ```
45
+
46
+ **Extension** — commands execute in the service worker via `playwright-crx`:
47
+ ```
48
+ ┌─────────────────────────┐
49
+ │ Extension (Side Panel) │
50
+ │ chrome.runtime.sendMessage({ type: 'run', command })
51
+ └────────────┬────────────┘
52
+
53
+
54
+ ┌──────────────────────────────┐
55
+ │ background.ts │
56
+ │ (playwright-crx service worker)
57
+ │ crxApp.attach(tabId) │
58
+ └────────────┬─────────────────┘
59
+ │ chrome.debugger API (CDP)
60
+
61
+ ┌─────────────┐
62
+ │ Chrome │
63
+ └─────────────┘
64
+ ```
65
+
66
+ The extension is **self-contained** — no external server or CLI process is required.
67
+
68
+ ### CLI Connection Modes
69
+
70
+ | Mode | Flag | Browser Source | Use Case |
71
+ |------|------|---------------|----------|
72
+ | **Launch** | `--headed` (default) | Launches new Chromium via Playwright | General automation |
73
+ | **Connect** | `--connect [port]` | Existing Chrome with `--remote-debugging-port` | Debug running app |
74
+
75
+ ## Quick Start — CLI
76
+
77
+ ```bash
78
+ # Install
79
+ npm install -g playwright-repl
80
+ npx playwright install # browser binaries (if needed)
81
+
82
+ # Start the REPL (launches browser automatically)
83
+ playwright-repl
84
+
85
+ # With a visible browser
86
+ playwright-repl --headed
87
+
88
+ # Connect to existing Chrome
89
+ playwright-repl --connect 9222
90
+ ```
91
+
92
+ ```
93
+ pw> goto https://demo.playwright.dev/todomvc/
94
+ pw> fill "What needs to be done?" "Buy groceries"
95
+ pw> press Enter
96
+ pw> fill "What needs to be done?" "Write tests"
97
+ pw> press Enter
98
+ pw> check "Buy groceries"
99
+ pw> verify-text "1 item left"
100
+ ```
101
+
102
+ ## Quick Start — Extension
103
+
104
+ The extension works without any external server. Just load it in Chrome:
105
+
106
+ ```bash
107
+ # Build the extension
108
+ cd packages/extension && npm run build
109
+
110
+ # Load in Chrome: chrome://extensions → Enable Developer mode → Load unpacked → select packages/extension/dist/
111
+ ```
112
+
113
+ Or install from the Chrome Web Store (coming soon).
114
+
115
+ Once loaded:
116
+ 1. Click the extension icon to open the **Playwright REPL** side panel
117
+ 2. The panel auto-attaches to the active tab — the status dot turns green
118
+ 3. Type commands in the panel — same syntax as CLI
119
+
120
+ The extension panel includes a REPL input, script editor, visual recorder, and export to Playwright tests.
121
+
122
+ **Open as popup window:** Right-click the extension icon → **Options** → select "Popup Window". Click the icon and the REPL opens as a standalone 450×700 window attached to the current tab. Use the **tab switcher** in the toolbar to re-attach to a different tab at any time.
123
+
124
+ ## Install
125
+
126
+ ```bash
127
+ npm install -g playwright-repl
128
+
129
+ # If you don't have browser binaries yet
130
+ npx playwright install
131
+
132
+ # Or install from source
133
+ git clone https://github.com/stevez/playwright-repl.git
134
+ cd playwright-repl && npm install && npm link
135
+ ```
136
+
137
+ ## Usage
138
+
139
+ ```bash
140
+ # Interactive REPL
141
+ playwright-repl [options]
142
+
143
+ # Replay a recorded session
144
+ playwright-repl --replay session.pw
145
+
146
+ # Replay all .pw files in a folder
147
+ playwright-repl --replay examples/
148
+
149
+ # Replay multiple files
150
+ playwright-repl --replay a.pw b.pw c.pw
151
+
152
+ # Step through replay (pause between commands)
153
+ playwright-repl --replay session.pw --step
154
+
155
+ # Start REPL with recording enabled
156
+ playwright-repl --record my-test.pw
157
+
158
+ # Pipe commands
159
+ echo -e "goto https://example.com\nsnapshot" | playwright-repl
160
+
161
+ # Connect to existing Chrome via CDP
162
+ playwright-repl --connect # default port 9222
163
+ playwright-repl --connect 9333 # custom port
164
+
165
+ ```
166
+
167
+ ### CLI Options
168
+
169
+ | Option | Description |
170
+ |--------|-------------|
171
+ | `-b, --browser <type>` | Browser: `chrome`, `firefox`, `webkit`, `msedge` |
172
+ | `--headed` | Run browser in headed (visible) mode |
173
+ | `--persistent` | Use persistent browser profile |
174
+ | `--profile <dir>` | Persistent profile directory |
175
+ | `--connect [port]` | Connect to existing Chrome via CDP (default: `9222`) |
176
+ | `--extension` | Launch Chrome with side panel extension and HTTP command server (legacy) |
177
+ | `--port <number>` | Command server port for `--extension` mode (default: `6781`) |
178
+ | `--config <file>` | Path to config file |
179
+ | `--replay <files...>` | Replay `.pw` file(s) or folder(s) |
180
+ | `--record <file>` | Start REPL with recording to file |
181
+ | `--step` | Pause between commands during replay |
182
+ | `-q, --silent` | Suppress banner and status messages |
183
+ | `-h, --help` | Show help |
184
+
185
+ ## Commands
186
+
187
+ All commands work in both CLI and extension. In the CLI, type directly at the `pw>` prompt. In the extension, type in the REPL input or use the script editor.
188
+
189
+ ### Navigation
190
+
191
+ | Command | Alias | Description |
192
+ |---------|-------|-------------|
193
+ | `goto <url>` | `g` | Navigate to a URL |
194
+ | `open [url]` | `o` | Open browser (optionally navigate) |
195
+ | `go-back` | `back` | Go back in history |
196
+ | `go-forward` | `fwd` | Go forward in history |
197
+ | `reload` | `r` | Reload page |
198
+
199
+ ### Interaction
200
+
201
+ | Command | Alias | Description |
202
+ |---------|-------|-------------|
203
+ | `click <ref>` | `c` | Click an element |
204
+ | `dblclick <ref>` | `dc` | Double-click an element |
205
+ | `fill <ref> <text>` | `f` | Fill a form field |
206
+ | `type <text>` | `t` | Type text key by key |
207
+ | `press <key>` | `p` | Press a keyboard key |
208
+ | `hover <ref>` | `h` | Hover over element |
209
+ | `select <ref> <value>` | `sel` | Select dropdown option |
210
+ | `check <ref>` | `chk` | Check a checkbox |
211
+ | `uncheck <ref>` | `unchk` | Uncheck a checkbox |
212
+ | `upload <ref> <file>` | — | Upload a file |
213
+ | `drag <from> <to>` | — | Drag and drop |
214
+
215
+ ### Inspection
216
+
217
+ | Command | Alias | Description |
218
+ |---------|-------|-------------|
219
+ | `snapshot` | `s` | Accessibility tree with element refs |
220
+ | `screenshot` | `ss` | Take a screenshot |
221
+ | `eval <expr>` | `e` | Evaluate JavaScript in browser context |
222
+ | `console` | `con` | Browser console messages |
223
+ | `network` | `net` | Network requests log |
224
+ | `run-code <code>` | — | Run Playwright code with `page` object |
225
+
226
+ ### Assertions
227
+
228
+ | Command | Alias | Description |
229
+ |---------|-------|-------------|
230
+ | `verify-text <text>` | `vt` | Verify text is visible on page |
231
+ | `verify-element <role> <name>` | `ve` | Verify element exists by role and name |
232
+ | `verify-value <ref> <value>` | `vv` | Verify input/select/checkbox value |
233
+ | `verify-list <ref> <items>` | `vl` | Verify list contains expected items |
234
+
235
+ ### Tabs
236
+
237
+ | Command | Alias | Description |
238
+ |---------|-------|-------------|
239
+ | `tab-list` | `tl` | List open tabs |
240
+ | `tab-new [url]` | `tn` | Open a new tab |
241
+ | `tab-close [index]` | `tc` | Close a tab |
242
+ | `tab-select <index>` | `ts` | Switch to a tab |
243
+
244
+ ### Storage & Cookies
245
+
246
+ | Command | Description |
247
+ |---------|-------------|
248
+ | `state-save [file]` | Save auth state (cookies + storage) |
249
+ | `state-load <file>` | Load auth state |
250
+ | `cookie-list` | List all cookies |
251
+ | `cookie-get <name>` | Get a specific cookie |
252
+ | `cookie-set <name> <value>` | Set a cookie |
253
+ | `cookie-delete <name>` | Delete a cookie |
254
+ | `cookie-clear` | Clear all cookies |
255
+ | `localstorage-list` | List all localStorage |
256
+ | `localstorage-get <key>` | Get localStorage value |
257
+ | `localstorage-set <key> <value>` | Set localStorage value |
258
+ | `localstorage-delete <key>` | Delete localStorage key |
259
+ | `localstorage-clear` | Clear all localStorage |
260
+ | `sessionstorage-list` | List all sessionStorage |
261
+ | `sessionstorage-get <key>` | Get sessionStorage value |
262
+ | `sessionstorage-set <key> <value>` | Set sessionStorage value |
263
+ | `sessionstorage-delete <key>` | Delete sessionStorage key |
264
+ | `sessionstorage-clear` | Clear all sessionStorage |
265
+
266
+ ### Network Routing
267
+
268
+ | Command | Description |
269
+ |---------|-------------|
270
+ | `route <pattern>` | Intercept network requests |
271
+ | `route-list` | List active routes |
272
+ | `unroute [pattern]` | Remove route(s) |
273
+
274
+ ### Dialogs & Layout
275
+
276
+ | Command | Description |
277
+ |---------|-------------|
278
+ | `dialog-accept [text]` | Accept a browser dialog |
279
+ | `dialog-dismiss` | Dismiss a browser dialog |
280
+ | `resize <w> <h>` | Resize browser window |
281
+ | `pdf` | Save page as PDF |
282
+
283
+ ### Browser Control
284
+
285
+ | Command | Alias | Description |
286
+ |---------|-------|-------------|
287
+ | `close` | `q` | Close the browser |
288
+ | `config-print` | — | Print browser config |
289
+
290
+ ## CLI Features
291
+
292
+ ### REPL Meta-Commands
293
+
294
+ | Command | Description |
295
+ |---------|-------------|
296
+ | `.help` | Show available commands |
297
+ | `.aliases` | Show all command aliases |
298
+ | `.status` | Show connection status |
299
+ | `.reconnect` | Restart browser |
300
+ | `.record [file]` | Start recording commands |
301
+ | `.save` | Stop recording and save to file |
302
+ | `.pause` | Pause/resume recording |
303
+ | `.discard` | Discard current recording |
304
+ | `.replay <file>` | Replay a recorded session |
305
+ | `.exit` | Exit REPL (also Ctrl+D) |
306
+
307
+ ### Session Recording & Replay
308
+
309
+ Record your browser interactions and replay them later — great for regression tests, onboarding demos, or sharing reproducible flows.
310
+
311
+ #### Record
312
+
313
+ ```bash
314
+ # From CLI
315
+ playwright-repl --record my-test.pw --headed
316
+
317
+ # Or inside the REPL
318
+ pw> .record my-test
319
+ ⏺ Recording to my-test.pw
320
+ pw> goto https://demo.playwright.dev/todomvc/
321
+ pw> fill "What needs to be done?" "Buy groceries"
322
+ pw> press Enter
323
+ pw> verify-text "1 item left"
324
+ pw> .save
325
+ ✓ Saved 4 commands to my-test.pw
326
+ ```
327
+
328
+ #### Replay
329
+
330
+ ```bash
331
+ # Full speed
332
+ playwright-repl --replay my-test.pw
333
+
334
+ # Step-through (press Enter between commands)
335
+ playwright-repl --replay my-test.pw --step --headed
336
+
337
+ # Replay all .pw files in a folder (multi-file mode)
338
+ playwright-repl --replay examples/ --silent
339
+
340
+ # Or inside the REPL
341
+ pw> .replay my-test.pw
342
+ ```
343
+
344
+ Multi-file replay runs all files sequentially, writes a `replay-<timestamp>.log` with per-command results, and prints a pass/fail summary. Exit code 0 if all pass, 1 if any fail.
345
+
346
+ #### File Format
347
+
348
+ `.pw` files are plain text — human-readable, diffable, version-controllable:
349
+
350
+ ```
351
+ # CI smoke test — quick add-and-verify
352
+ # App: https://demo.playwright.dev/todomvc/
353
+
354
+ goto https://demo.playwright.dev/todomvc/
355
+ fill "What needs to be done?" "Buy groceries"
356
+ press Enter
357
+ verify-text "Buy groceries"
358
+ verify-text "1 item left"
359
+ ```
360
+
361
+ #### Recording Controls
362
+
363
+ | Command | Description |
364
+ |---------|-------------|
365
+ | `.record [file]` | Start recording |
366
+ | `.pause` | Pause recording (toggle) |
367
+ | `.save` | Stop and save to file |
368
+ | `.discard` | Discard without saving |
369
+
370
+ ### eval & run-code
371
+
372
+ Two ways to run custom code from the REPL:
373
+
374
+ #### eval — Browser Context
375
+
376
+ Runs JavaScript inside the browser page (via `page.evaluate`). Use browser globals like `document`, `window`, `location`:
377
+
378
+ ```
379
+ pw> eval document.title
380
+ "Installation | Playwright"
381
+
382
+ pw> eval window.location.href
383
+ "https://playwright.dev/docs/intro"
384
+
385
+ pw> eval document.querySelectorAll('a').length
386
+ 42
387
+ ```
388
+
389
+ #### run-code — Playwright API
390
+
391
+ Runs code with full access to the Playwright `page` object. The REPL auto-wraps your code — just write the body:
392
+
393
+ ```
394
+ pw> run-code page.url()
395
+ → async (page) => { return await page.url() }
396
+ "https://playwright.dev/docs/intro"
397
+
398
+ pw> run-code page.locator('h1').textContent()
399
+ → async (page) => { return await page.locator('h1').textContent() }
400
+ "Installation"
401
+ ```
402
+
403
+ For multiple statements, use semicolons:
404
+
405
+ ```
406
+ pw> run-code const u = await page.url(); const t = await page.title(); return {u, t}
407
+ ```
408
+
409
+ ## Extension Features
410
+
411
+ ### Side Panel and Popup Window
412
+
413
+ The extension opens as a Chrome **side panel** by default. To switch to a standalone **popup window**, right-click the extension icon → **Options** and choose "Open as Popup Window". Your preference is saved and applied every time you click the icon.
414
+
415
+ The panel UI is the same in both modes:
416
+
417
+ - **REPL input** — type commands at the bottom, results appear in the console pane
418
+ - **Script editor** — write multi-line `.pw` scripts with line numbers, run all or step through
419
+ - **Visual recorder** — click Record, interact with the page, recorded commands appear automatically
420
+ - **Export** — convert `.pw` commands to Playwright TypeScript test code
421
+ - **Tab switcher** — toolbar dropdown lets you re-attach the panel to any open browser tab without reopening
422
+ - **Light/dark themes** — matches your DevTools theme
423
+
424
+ ### Recording in Extension
425
+
426
+ Click the **Record** button in the toolbar, then interact with the page normally. The recorder uses playwright-crx's built-in CDP recorder to capture:
427
+
428
+ - **Navigation** — `goto` commands on page load
429
+ - **Clicks** — with text and ARIA role locators
430
+ - **Form input** — fill commands
431
+ - **Key presses** — Enter, Tab, Escape
432
+
433
+ Recorded commands appear in the script editor in real time. Click **Stop** when done.
434
+
435
+ ### Export to Playwright
436
+
437
+ The extension can export `.pw` commands to Playwright TypeScript:
438
+
439
+ ```
440
+ # .pw commands → Playwright TypeScript
441
+ goto https://example.com → await page.goto("https://example.com");
442
+ click "Submit" → await page.getByText("Submit").click();
443
+ fill "Email" "test@example.com" → await page.getByLabel("Email").fill("test@example.com");
444
+ verify-text "Success" → await expect(page.getByText("Success")).toBeVisible();
445
+ ```
446
+
447
+ ### Connect Mode
448
+
449
+ To control an existing Chrome instance from the CLI:
450
+
451
+ ```bash
452
+ # Start Chrome with debugging port
453
+ chrome --remote-debugging-port=9222
454
+
455
+ # Connect the REPL
456
+ playwright-repl --connect 9222
457
+ ```
458
+
459
+ ## Examples
460
+
461
+ Examples use the [TodoMVC demo](https://demo.playwright.dev/todomvc/) and [playwright.dev](https://playwright.dev/). All can be run directly or together via multi-file replay:
462
+
463
+ | File | Description |
464
+ |------|-------------|
465
+ | [01-add-todos.pw](packages/cli/examples/01-add-todos.pw) | Add todos and verify with assertions |
466
+ | [02-complete-and-filter.pw](packages/cli/examples/02-complete-and-filter.pw) | Complete todos, use filters |
467
+ | [03-record-session.pw](packages/cli/examples/03-record-session.pw) | Record a test session |
468
+ | [04-replay-session.pw](packages/cli/examples/04-replay-session.pw) | Replay with step-through |
469
+ | [05-ci-pipe.pw](packages/cli/examples/05-ci-pipe.pw) | CI smoke test |
470
+ | [06-edit-todo.pw](packages/cli/examples/06-edit-todo.pw) | Double-click to edit a todo |
471
+ | [07-test-click-nth.pw](packages/cli/examples/07-test-click-nth.pw) | `--nth` disambiguation on playwright.dev |
472
+ | [08-localstorage.pw](packages/cli/examples/08-localstorage.pw) | localStorage commands: list, clear, reload |
473
+
474
+ Try one:
475
+
476
+ ```bash
477
+ # Run an example with a visible browser
478
+ playwright-repl --replay packages/cli/examples/01-add-todos.pw --headed
479
+
480
+ # Step through an example interactively
481
+ playwright-repl --replay packages/cli/examples/04-replay-session.pw --step --headed
482
+
483
+ # Run as a CI smoke test (headless, silent)
484
+ playwright-repl --replay packages/cli/examples/05-ci-pipe.pw --silent
485
+
486
+ # Run all examples (multi-file replay with log report)
487
+ playwright-repl --replay packages/cli/examples/ --silent
488
+ ```
489
+
490
+ ## Monorepo Structure
491
+
492
+ ```
493
+ packages/
494
+ ├── core/ # Engine + shared utilities (TypeScript, tsc)
495
+ │ └── src/
496
+ │ ├── engine.ts # Wraps BrowserServerBackend in-process
497
+ │ ├── extension-server.ts # HTTP server (CLI --extension mode)
498
+ │ ├── parser.ts # Command parsing and alias resolution
499
+ │ ├── page-scripts.ts # Text locator and assertion helpers
500
+ │ ├── completion-data.ts # Ghost completion items
501
+ │ ├── colors.ts # ANSI color helpers
502
+ │ └── resolve.ts # COMMANDS map, minimist re-export
503
+ ├── cli/ # Terminal REPL (TypeScript, tsc)
504
+ │ └── src/
505
+ │ ├── playwright-repl.ts # CLI entry point
506
+ │ ├── repl.ts # Interactive readline loop
507
+ │ ├── recorder.ts # Session recording/replay
508
+ │ └── index.ts # Public API exports
509
+ └── extension/ # Chrome side panel extension (React, Vite, Tailwind)
510
+ ├── src/
511
+ │ ├── background.ts # Service worker — playwright-crx command execution + recording
512
+ │ ├── commands.ts # Keyword → Playwright function mapping
513
+ │ ├── page-scripts.ts # Text locator and assertion helpers (extension)
514
+ │ ├── panel/ # Side panel UI (React)
515
+ │ │ ├── panel.html
516
+ │ │ ├── panel.tsx # React entry point
517
+ │ │ ├── panel.css # Theme variables + residual styles
518
+ │ │ ├── App.tsx # Root component (auto-attach, tab listener)
519
+ │ │ ├── reducer.ts # useReducer state management
520
+ │ │ ├── types.ts # TypeScript types
521
+ │ │ ├── components/ # Toolbar, CommandInput, EditorPane, ConsolePane, etc.
522
+ │ │ └── lib/ # bridge, run, commands, autocomplete, command-history, etc.
523
+ └── public/
524
+ └── manifest.json # Manifest V3 config (requires "debugger" permission)
525
+ ```
526
+
527
+ ## Requirements
528
+
529
+ - **Node.js** >= 20
530
+ - **playwright** >= 1.59.0-alpha (includes `lib/mcp/browser/` engine)
531
+
532
+ ## License
533
+
534
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playwright-repl",
3
- "version": "0.7.13",
3
+ "version": "0.9.0",
4
4
  "description": "Interactive REPL for Playwright browser automation — keyword-driven testing from your terminal",
5
5
  "type": "module",
6
6
  "bin": {
@@ -38,8 +38,9 @@
38
38
  "node": ">=20.0.0"
39
39
  },
40
40
  "dependencies": {
41
- "@playwright-repl/core": "0.7.13",
42
- "playwright": "1.59.0-alpha-2026-02-21"
41
+ "@playwright-repl/core": "workspace:*",
42
+ "playwright": "1.59.0-alpha-2026-02-21",
43
+ "playwright-core": "1.59.0-alpha-2026-02-21"
43
44
  },
44
45
  "devDependencies": {
45
46
  "vitest": "^4.0.18"