@playwright-repl/browser-extension 0.24.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.
- package/LICENSE +21 -0
- package/README.md +176 -0
- package/dist/background.js +162567 -0
- package/dist/background.js.map +1 -0
- package/dist/content/recorder.js +479 -0
- package/dist/content/trace-loader.js +12 -0
- package/dist/devtools/console.html +17 -0
- package/dist/devtools/console.js +44 -0
- package/dist/devtools/console.js.map +1 -0
- package/dist/devtools/devtools.html +8 -0
- package/dist/devtools/devtools.js +7 -0
- package/dist/devtools/devtools.js.map +1 -0
- package/dist/icons/dramaturg_icon_128.png +0 -0
- package/dist/icons/dramaturg_icon_16.png +0 -0
- package/dist/icons/dramaturg_icon_32.png +0 -0
- package/dist/icons/dramaturg_icon_48.png +0 -0
- package/dist/index.css +1353 -0
- package/dist/index.js +12462 -0
- package/dist/index.js.map +1 -0
- package/dist/index2.js +27328 -0
- package/dist/index2.js.map +1 -0
- package/dist/manifest.json +49 -0
- package/dist/modulepreload-polyfill.js +30 -0
- package/dist/modulepreload-polyfill.js.map +1 -0
- package/dist/offscreen/offscreen.html +6 -0
- package/dist/offscreen/offscreen.js +151 -0
- package/dist/offscreen/offscreen.js.map +1 -0
- package/dist/panel/panel.html +16 -0
- package/dist/panel/panel.js +2258 -0
- package/dist/panel/panel.js.map +1 -0
- package/dist/preferences/preferences.html +14 -0
- package/dist/preferences/preferences.js +102 -0
- package/dist/preferences/preferences.js.map +1 -0
- package/dist/settings.js +13 -0
- package/dist/settings.js.map +1 -0
- package/dist/sw-debugger-core.js +1139 -0
- package/dist/sw-debugger-core.js.map +1 -0
- package/package.json +80 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Steve Zhang
|
|
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,176 @@
|
|
|
1
|
+
# <img src="public/icons/dramaturg_icon_128.png" width="48" height="48" align="center"> Dramaturg
|
|
2
|
+
|
|
3
|
+
Chrome side panel extension that runs the full Playwright API directly inside your browser — no Node.js backend required. Use it as a standalone console, or connect it to the CLI / MCP server.
|
|
4
|
+
|
|
5
|
+
| Feature | Description |
|
|
6
|
+
|---------|-------------|
|
|
7
|
+
| **Console** | Auto-detects input type — `.pw` keywords or Playwright API / JavaScript |
|
|
8
|
+
| **Script Editor** | Syntax highlighting, pass/fail gutter, autocomplete, run/step/stop |
|
|
9
|
+
| **JS Debugger** | Breakpoints, step over/into/out, variables with scope inspection |
|
|
10
|
+
| **Recorder** | Captures clicks, fills, navigations as `.pw` commands and Playwright code |
|
|
11
|
+
| **Object Tree** | Expandable CDP object tree, like Chrome DevTools |
|
|
12
|
+
| **Tab Switcher** | Switch active target to any open tab from the toolbar |
|
|
13
|
+
| **Preferences** | Language mode, bridge port, open mode — configurable in Options |
|
|
14
|
+
| **Light / Dark** | Toggle themes from toolbar, persisted across sessions |
|
|
15
|
+
| **DevTools REPL** | Console-only tab in Chrome DevTools for quick debugging |
|
|
16
|
+
|
|
17
|
+
## Setup
|
|
18
|
+
|
|
19
|
+
1. Install from the [Chrome Web Store](https://chromewebstore.google.com/detail/dramaturg/ppbkmncnmjkfppilnmplpokdfagobipa), or build from source:
|
|
20
|
+
```bash
|
|
21
|
+
npm run build # from packages/extension/
|
|
22
|
+
```
|
|
23
|
+
Then open `chrome://extensions` → enable **Developer mode** → **Load unpacked** → select `packages/extension/dist/`
|
|
24
|
+
2. Click the **Dramaturg** icon to open the side panel
|
|
25
|
+
|
|
26
|
+
## Console
|
|
27
|
+
|
|
28
|
+
Auto-detects what you type and routes it to the right executor:
|
|
29
|
+
|
|
30
|
+
| What you type | Mode | Runs in |
|
|
31
|
+
|---|---|---|
|
|
32
|
+
| `goto`, `click`, `snapshot`, ... | **Keyword** | Playwright via service worker |
|
|
33
|
+
| `await page.title()`, `1 + 1`, `fetch(...)` | **Playwright API / JS** | Service worker (`page`, `context`, `expect` available) |
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
> snapshot ← keyword command
|
|
37
|
+
→ ### Page ...
|
|
38
|
+
|
|
39
|
+
> await page.locator('h1').textContent() ← Playwright API
|
|
40
|
+
→ "Fast and reliable end-to-end testing"
|
|
41
|
+
|
|
42
|
+
> await page.evaluate(() => document.title) ← DOM access via page.evaluate
|
|
43
|
+
→ "Playwright"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
JS mode runs in an async context — top-level `await`, promises, template literals, variables, and IIFEs all work naturally.
|
|
47
|
+
|
|
48
|
+
Results render as an **expandable object tree** — click any object to lazily fetch its properties.
|
|
49
|
+
|
|
50
|
+
- **Command history** — Up/Down arrows
|
|
51
|
+
- **Autocomplete** — `.pw` keyword and Playwright API ghost-text suggestions
|
|
52
|
+
- **Screenshot preview** — inline image with click-to-expand lightbox
|
|
53
|
+
- **Ctrl+L / `.clear`** — clear console output
|
|
54
|
+
|
|
55
|
+
## Script Editor
|
|
56
|
+
|
|
57
|
+
Write and run multi-line `.pw` scripts or JavaScript directly in the panel:
|
|
58
|
+
|
|
59
|
+
- **Syntax highlighting** — `.pw` keywords, strings, comments; full JS highlighting in JS mode
|
|
60
|
+
- **Autocomplete** — Playwright API and keyword ghost-text suggestions
|
|
61
|
+
- **Pass/fail gutter** — check/cross markers per line after execution
|
|
62
|
+
- **Run / Step / Stop** — run all lines, step through one at a time, or abort
|
|
63
|
+
- **JS debugger** — pauses at each line with inline variable values
|
|
64
|
+
- **Open / Save** — load `.pw` or `.js` files from disk; save with timestamp filename
|
|
65
|
+
- **Ctrl+Enter** — run the script from keyboard
|
|
66
|
+
|
|
67
|
+
## Recording
|
|
68
|
+
|
|
69
|
+
Click **Record**, interact with the page — clicks, hovers, fills, and navigations are captured and inserted into the editor at the cursor:
|
|
70
|
+
|
|
71
|
+
- **`.pw` commands** — `goto`, `click`, `fill`, `press` — ready to replay
|
|
72
|
+
- **JS Playwright code** — `await page.click(...)` — ready to paste into a test
|
|
73
|
+
|
|
74
|
+
Ambiguous elements are disambiguated with ancestor context (e.g. `click "Save" --in "Settings"`).
|
|
75
|
+
|
|
76
|
+
## Tab Management
|
|
77
|
+
|
|
78
|
+
- **Tab switcher dropdown** — lists all open tabs; switch active target without leaving the panel
|
|
79
|
+
- **Auto-attach** — attaches to the active tab automatically when the panel opens
|
|
80
|
+
- **Connection status** — color-coded indicator (green / yellow / red)
|
|
81
|
+
- **Attach button** — manually re-attach after tab navigation
|
|
82
|
+
|
|
83
|
+
## Connect to CLI (Bridge Mode)
|
|
84
|
+
|
|
85
|
+
The extension connects to the CLI bridge server automatically:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
playwright-repl --bridge # start the CLI bridge server
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Your terminal becomes a remote console for the browser — commands execute in your real Chrome session.
|
|
92
|
+
|
|
93
|
+
See [packages/cli/README.md](../cli/README.md) for CLI setup.
|
|
94
|
+
|
|
95
|
+
## Connect to MCP Server (AI Browser Agent)
|
|
96
|
+
|
|
97
|
+
The extension connects to the `@playwright-repl/mcp` server for AI-driven automation:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
npm install -g @playwright-repl/mcp
|
|
101
|
+
playwright-repl-mcp # starts the MCP bridge server
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
See [packages/mcp/README.md](../mcp/README.md) for MCP setup.
|
|
105
|
+
|
|
106
|
+
## What Makes This Unique
|
|
107
|
+
|
|
108
|
+
Most browser automation tools require a Node.js backend. This extension runs Playwright — `page`, `context`, `expect`, locators, assertions — entirely inside Chrome.
|
|
109
|
+
|
|
110
|
+
| | Node + Playwright | Chrome DevTools | **Dramaturg** |
|
|
111
|
+
|---|---|---|---|
|
|
112
|
+
| Runs Playwright | Node process | No | Service worker |
|
|
113
|
+
| Full `page.*` API | Yes | No | Yes |
|
|
114
|
+
| `expect()` in console | Test runner only | No | Yes, interactively |
|
|
115
|
+
| JS in page context | via `page.evaluate` | Yes | Yes |
|
|
116
|
+
| CDP object tree | No | Yes | Yes |
|
|
117
|
+
| Real attached tab | No (separate launch) | Yes | Yes |
|
|
118
|
+
|
|
119
|
+
## Architecture
|
|
120
|
+
|
|
121
|
+
Two technologies make Playwright run inside the browser:
|
|
122
|
+
|
|
123
|
+
**1. playwright-crx** — replaces Playwright's CDP WebSocket with `chrome.debugger`, enabling the full Playwright API inside a Chrome extension's service worker.
|
|
124
|
+
|
|
125
|
+
**2. swDebugEval** — the panel evaluates expressions in the service worker's runtime via `chrome.debugger`, where live Playwright globals (`page`, `context`, `expect`) exist.
|
|
126
|
+
|
|
127
|
+
### Command Execution Pipeline
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
Side Panel (React)
|
|
131
|
+
CommandInput → runAndDispatch()
|
|
132
|
+
│ string: e.g. "click Submit"
|
|
133
|
+
▼
|
|
134
|
+
commands.ts — parseReplCommand()
|
|
135
|
+
Compiles keyword → jsExpr string
|
|
136
|
+
│
|
|
137
|
+
▼
|
|
138
|
+
bridge.ts — executeCommand()
|
|
139
|
+
Calls swDebugEval(jsExpr)
|
|
140
|
+
│ chrome.debugger.sendCommand('Runtime.evaluate')
|
|
141
|
+
▼
|
|
142
|
+
Service Worker (background.ts)
|
|
143
|
+
Live globals: page, context, crxApp, expect
|
|
144
|
+
│ playwright-crx (CDP)
|
|
145
|
+
▼
|
|
146
|
+
Chrome tab
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### background.ts — Message Types
|
|
150
|
+
|
|
151
|
+
| Message type | Action |
|
|
152
|
+
|---|---|
|
|
153
|
+
| `bridge-command` | Parses and executes CLI/MCP commands |
|
|
154
|
+
| `attach` | `crxApp.attach(tabId)` — connects to tab |
|
|
155
|
+
| `record-start` | Injects recorder into active tab |
|
|
156
|
+
| `record-stop` | Disconnects recorder |
|
|
157
|
+
| `health` | Returns `{ ok: !!crxApp }` |
|
|
158
|
+
| `get-bridge-port` | Returns bridge port from `chrome.storage` |
|
|
159
|
+
|
|
160
|
+
## Build & Test
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
cd packages/extension
|
|
164
|
+
|
|
165
|
+
# Build
|
|
166
|
+
npm run build
|
|
167
|
+
|
|
168
|
+
# Unit tests (Vitest browser mode)
|
|
169
|
+
npm run test
|
|
170
|
+
|
|
171
|
+
# E2E tests (Playwright)
|
|
172
|
+
npm run test:e2e
|
|
173
|
+
npx playwright test e2e/panel
|
|
174
|
+
npx playwright test e2e/commands
|
|
175
|
+
npx playwright test e2e/recording
|
|
176
|
+
```
|