@presto1314w/vite-devtools-browser 0.3.2 → 0.3.5
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 -21
- package/README.md +135 -320
- package/dist/browser-session.d.ts +11 -1
- package/dist/browser-session.js +29 -40
- package/dist/browser.d.ts +11 -0
- package/dist/browser.js +19 -1
- package/dist/cli.js +57 -57
- package/dist/client.js +2 -2
- package/dist/daemon.js +91 -18
- package/dist/event-queue.d.ts +10 -1
- package/dist/event-queue.js +52 -2
- package/dist/paths.d.ts +25 -0
- package/dist/paths.js +42 -4
- package/dist/react/hook-manager.d.ts +29 -0
- package/dist/react/hook-manager.js +75 -0
- package/dist/react/hook.d.ts +1 -0
- package/dist/react/hook.js +227 -0
- package/dist/react/profiler.d.ts +55 -0
- package/dist/react/profiler.js +166 -0
- package/dist/react/zustand.d.ts +31 -0
- package/dist/react/zustand.js +113 -0
- package/dist/trace.js +5 -4
- package/dist/vue/devtools.d.ts +1 -1
- package/dist/vue/devtools.js +41 -3
- package/package.json +69 -65
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Vercel, Inc.
|
|
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.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vercel, Inc.
|
|
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
CHANGED
|
@@ -1,320 +1,135 @@
|
|
|
1
|
-
# vite-browser
|
|
2
|
-
|
|
3
|
-
**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
The
|
|
27
|
-
|
|
28
|
-
You
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
## Core Capabilities
|
|
137
|
-
|
|
138
|
-
**Framework detection**
|
|
139
|
-
- Vue, React, Svelte best-effort detection with version hinting
|
|
140
|
-
|
|
141
|
-
**Vue runtime**
|
|
142
|
-
- component tree and details
|
|
143
|
-
- Pinia stores, getters, and changed keys
|
|
144
|
-
- Vue Router state
|
|
145
|
-
|
|
146
|
-
**React runtime**
|
|
147
|
-
- component tree with props, state, hooks, context, and source metadata
|
|
148
|
-
|
|
149
|
-
**Svelte runtime**
|
|
150
|
-
- component tree when metadata is available
|
|
151
|
-
|
|
152
|
-
**Vite runtime diagnostics**
|
|
153
|
-
- runtime status and HMR health
|
|
154
|
-
- HMR timeline, summary, and clear
|
|
155
|
-
- module graph snapshot, diff, trace, and clear
|
|
156
|
-
- error / HMR correlation over configurable time windows
|
|
157
|
-
- store and module update / render path correlation
|
|
158
|
-
- propagation diagnosis with store updates, changed keys, and render paths
|
|
159
|
-
- rule-based HMR diagnosis with confidence levels
|
|
160
|
-
- source-mapped errors with optional inline source snippets
|
|
161
|
-
|
|
162
|
-
**Debug utilities**
|
|
163
|
-
- console logs, network tracing, screenshot, page `eval`
|
|
164
|
-
|
|
165
|
-
---
|
|
166
|
-
|
|
167
|
-
## Positioning
|
|
168
|
-
|
|
169
|
-
| Tool | Best for | Gap vs `vite-browser` |
|
|
170
|
-
|---|---|---|
|
|
171
|
-
| `agent-browser` | general browser automation | no Vite runtime awareness |
|
|
172
|
-
| `next-browser` | Next.js + React debugging | not a Vite runtime tool |
|
|
173
|
-
| `vite-plugin-vue-mcp` | Vue MCP integration | requires plugin install, Vue only |
|
|
174
|
-
| `vite-browser` | Vite runtime diagnostics for agents and developers | browser lifecycle coverage still expanding |
|
|
175
|
-
|
|
176
|
-
`vite-browser` requires no changes to your project. It works against any running Vite dev server across Vue, React, and Svelte.
|
|
177
|
-
|
|
178
|
-
---
|
|
179
|
-
|
|
180
|
-
## Recommended Workflows
|
|
181
|
-
|
|
182
|
-
### HMR / runtime triage
|
|
183
|
-
```bash
|
|
184
|
-
vite-browser vite runtime
|
|
185
|
-
vite-browser errors --mapped --inline-source
|
|
186
|
-
vite-browser correlate errors --mapped --window 5000
|
|
187
|
-
vite-browser diagnose hmr --limit 50
|
|
188
|
-
vite-browser vite hmr trace --limit 50
|
|
189
|
-
vite-browser vite module-graph trace --limit 200
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
### Propagation / rerender triage
|
|
193
|
-
```bash
|
|
194
|
-
vite-browser correlate renders --window 5000
|
|
195
|
-
vite-browser diagnose propagation --window 5000
|
|
196
|
-
vite-browser vue pinia
|
|
197
|
-
vite-browser vue tree
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
### Data / API triage
|
|
201
|
-
```bash
|
|
202
|
-
vite-browser errors --mapped
|
|
203
|
-
vite-browser logs
|
|
204
|
-
vite-browser network
|
|
205
|
-
vite-browser network <idx>
|
|
206
|
-
vite-browser eval '<state probe>'
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
### Component / state triage
|
|
210
|
-
```bash
|
|
211
|
-
vite-browser detect
|
|
212
|
-
vite-browser vue tree
|
|
213
|
-
vite-browser vue pinia
|
|
214
|
-
vite-browser vue router
|
|
215
|
-
vite-browser react tree
|
|
216
|
-
vite-browser svelte tree
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
---
|
|
220
|
-
|
|
221
|
-
## Command Reference
|
|
222
|
-
|
|
223
|
-
### Browser
|
|
224
|
-
```bash
|
|
225
|
-
vite-browser open <url> [--cookies-json <file>]
|
|
226
|
-
vite-browser close
|
|
227
|
-
vite-browser goto <url>
|
|
228
|
-
vite-browser back
|
|
229
|
-
vite-browser reload
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
### Framework
|
|
233
|
-
```bash
|
|
234
|
-
vite-browser detect
|
|
235
|
-
vite-browser vue tree [id]
|
|
236
|
-
vite-browser vue pinia [store]
|
|
237
|
-
vite-browser vue router
|
|
238
|
-
vite-browser react tree [id]
|
|
239
|
-
vite-browser svelte tree [id]
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
### Vite Runtime
|
|
243
|
-
```bash
|
|
244
|
-
vite-browser vite restart
|
|
245
|
-
vite-browser vite runtime
|
|
246
|
-
vite-browser vite hmr
|
|
247
|
-
vite-browser vite hmr trace [--limit <n>]
|
|
248
|
-
vite-browser vite hmr clear
|
|
249
|
-
vite-browser vite module-graph [--filter <txt>] [--limit <n>]
|
|
250
|
-
vite-browser vite module-graph trace [--filter <txt>] [--limit <n>]
|
|
251
|
-
vite-browser vite module-graph clear
|
|
252
|
-
vite-browser errors
|
|
253
|
-
vite-browser errors --mapped
|
|
254
|
-
vite-browser errors --mapped --inline-source
|
|
255
|
-
vite-browser correlate errors [--window <ms>]
|
|
256
|
-
vite-browser correlate renders [--window <ms>]
|
|
257
|
-
vite-browser correlate errors --mapped --inline-source
|
|
258
|
-
vite-browser diagnose hmr [--window <ms>] [--limit <n>]
|
|
259
|
-
vite-browser diagnose propagation [--window <ms>]
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
### Utilities
|
|
263
|
-
```bash
|
|
264
|
-
vite-browser logs
|
|
265
|
-
vite-browser network [idx]
|
|
266
|
-
vite-browser screenshot
|
|
267
|
-
vite-browser eval <script>
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
---
|
|
271
|
-
|
|
272
|
-
## Current Boundaries
|
|
273
|
-
|
|
274
|
-
`v0.3.2` is strong at:
|
|
275
|
-
- surfacing runtime state as structured shell output
|
|
276
|
-
- linking current errors to recent HMR and module activity
|
|
277
|
-
- detecting common HMR failure patterns with confidence levels
|
|
278
|
-
- narrowing likely store/module -> render paths in Vue-first flows
|
|
279
|
-
- capturing browser-side runtime errors even when the Vite overlay is absent
|
|
280
|
-
- turning sparse live Vue/Pinia repro signals into actionable `store -> render -> error` guidance more reliably
|
|
281
|
-
|
|
282
|
-
`correlate renders` and `diagnose propagation` are **high-confidence propagation clues**, not strict causal proof. They do not reliably trace deep chains like `store -> component A -> component B -> error` across arbitrary graphs, and intentionally fall back to conservative output when evidence is incomplete.
|
|
283
|
-
|
|
284
|
-
React store inspection (Zustand, Redux) and deeper cross-framework propagation tracing are on the roadmap.
|
|
285
|
-
|
|
286
|
-
---
|
|
287
|
-
|
|
288
|
-
## Skill Packs
|
|
289
|
-
|
|
290
|
-
```
|
|
291
|
-
skills/vite-browser-core-debug/SKILL.md
|
|
292
|
-
skills/vite-browser-runtime-diagnostics/SKILL.md
|
|
293
|
-
skills/vite-browser-network-regression/SKILL.md
|
|
294
|
-
skills/vite-browser-release-smoke/SKILL.md
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
Router: [skills/SKILL.md](./skills/SKILL.md)
|
|
298
|
-
|
|
299
|
-
---
|
|
300
|
-
|
|
301
|
-
## Local Development
|
|
302
|
-
|
|
303
|
-
```bash
|
|
304
|
-
pnpm install
|
|
305
|
-
pnpm build
|
|
306
|
-
pnpm test
|
|
307
|
-
pnpm test:coverage
|
|
308
|
-
pnpm test:evals
|
|
309
|
-
pnpm test:evals:e2e
|
|
310
|
-
```
|
|
311
|
-
|
|
312
|
-
## Requirements
|
|
313
|
-
|
|
314
|
-
- Node.js `>=20`
|
|
315
|
-
- Chromium via Playwright
|
|
316
|
-
- Running Vite dev server
|
|
317
|
-
|
|
318
|
-
## License
|
|
319
|
-
|
|
320
|
-
MIT
|
|
1
|
+
# vite-browser
|
|
2
|
+
|
|
3
|
+
**Know why your Vite app broke — not just where.**
|
|
4
|
+
|
|
5
|
+
Runtime diagnostics CLI for Vite applications. Connect to a running dev server, correlate errors with recent HMR activity, trace store-to-render propagation paths, and inspect framework state — all from the terminal, with zero project setup.
|
|
6
|
+
|
|
7
|
+
Built for developers and AI coding agents alike.
|
|
8
|
+
|
|
9
|
+
📖 [Documentation](https://maplecity1314.github.io/vite-browser/) · 📦 [npm](https://www.npmjs.com/package/@presto1314w/vite-devtools-browser)
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
**Agent Skill** (recommended):
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx skills add MapleCity1314/vite-browser
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**CLI only:**
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install -g @presto1314w/vite-devtools-browser
|
|
23
|
+
npx playwright install chromium
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## The problem
|
|
27
|
+
|
|
28
|
+
You save a file. Vite hot-updates. The page breaks.
|
|
29
|
+
|
|
30
|
+
The error overlay tells you _what_ failed — but not _which update caused it_, how the change propagated through your component tree, or whether the real problem is a stale store, a broken import, or a network regression.
|
|
31
|
+
|
|
32
|
+
## What vite-browser does
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# 1. See the current error with source context
|
|
36
|
+
$ vite-browser errors --mapped --inline-source
|
|
37
|
+
|
|
38
|
+
TypeError: Cannot read properties of undefined (reading 'items')
|
|
39
|
+
→ /src/components/CartSummary.tsx:14:12
|
|
40
|
+
14 | total = cart.items.reduce(...)
|
|
41
|
+
|
|
42
|
+
# 2. Correlate with recent HMR activity
|
|
43
|
+
$ vite-browser correlate errors --mapped --window 5000
|
|
44
|
+
|
|
45
|
+
Confidence: high
|
|
46
|
+
HMR update observed within 5000ms of the current error
|
|
47
|
+
Matching modules: /src/store/cart.ts
|
|
48
|
+
|
|
49
|
+
# 3. Trace the propagation path
|
|
50
|
+
$ vite-browser diagnose propagation --window 5000
|
|
51
|
+
|
|
52
|
+
Status: fail | Confidence: high
|
|
53
|
+
Store → Render → Error path found:
|
|
54
|
+
store: cart (changedKeys: items)
|
|
55
|
+
render: AppShell > ShoppingCart > CartSummary
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Four commands. You know the store update broke the render path. You know where to fix it.
|
|
59
|
+
|
|
60
|
+
## Key features
|
|
61
|
+
|
|
62
|
+
- **Error correlation** — Match errors against recent HMR-updated modules within a time window
|
|
63
|
+
- **Propagation diagnosis** — Trace `store → render → error` paths with confidence levels
|
|
64
|
+
- **HMR diagnosis** — Detect patterns like `missing-module`, `circular-dependency`, `hmr-websocket-closed`
|
|
65
|
+
- **Framework inspection** — Vue trees, Pinia stores, Vue Router, React props/hooks/state, Svelte trees
|
|
66
|
+
- **Mapped errors** — Source-mapped stack traces with inline source snippets
|
|
67
|
+
- **Zero config** — No plugins, no project changes. Works with any running Vite dev server
|
|
68
|
+
|
|
69
|
+
## Agent Skills
|
|
70
|
+
|
|
71
|
+
`vite-browser` is designed skill-first. The skill router automatically picks the right debugging workflow based on the symptom:
|
|
72
|
+
|
|
73
|
+
| Symptom | Routed to |
|
|
74
|
+
|---|---|
|
|
75
|
+
| Broad / unclear failure | `core-debug` |
|
|
76
|
+
| Recent edit or HMR breakage | `runtime-diagnostics` |
|
|
77
|
+
| Wrong data or failed requests | `network-regression` |
|
|
78
|
+
| Pre-merge verification | `release-smoke` |
|
|
79
|
+
|
|
80
|
+
AI coding agents (Claude Code, Codex, Cursor) follow the structured workflow instead of guessing.
|
|
81
|
+
|
|
82
|
+
→ [Agent Skills guide](https://maplecity1314.github.io/vite-browser/guide/agent-skills) · [AI IDE Setup](https://maplecity1314.github.io/vite-browser/guide/ide-setup)
|
|
83
|
+
|
|
84
|
+
## Quick reference
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# Browser
|
|
88
|
+
vite-browser open <url> # Launch and navigate
|
|
89
|
+
vite-browser close # Close browser and daemon
|
|
90
|
+
|
|
91
|
+
# Diagnostics
|
|
92
|
+
vite-browser errors --mapped --inline-source
|
|
93
|
+
vite-browser correlate errors --mapped --window <ms>
|
|
94
|
+
vite-browser correlate renders --window <ms>
|
|
95
|
+
vite-browser diagnose hmr --limit <n>
|
|
96
|
+
vite-browser diagnose propagation --window <ms>
|
|
97
|
+
|
|
98
|
+
# Framework
|
|
99
|
+
vite-browser detect
|
|
100
|
+
vite-browser vue tree | vue pinia | vue router
|
|
101
|
+
vite-browser react tree
|
|
102
|
+
vite-browser svelte tree
|
|
103
|
+
|
|
104
|
+
# Vite runtime
|
|
105
|
+
vite-browser vite runtime
|
|
106
|
+
vite-browser vite hmr trace --limit <n>
|
|
107
|
+
vite-browser vite module-graph trace --limit <n>
|
|
108
|
+
|
|
109
|
+
# Utilities
|
|
110
|
+
vite-browser logs | network | screenshot | eval <script>
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
→ [Full CLI reference](https://maplecity1314.github.io/vite-browser/reference/cli)
|
|
114
|
+
|
|
115
|
+
## Current scope
|
|
116
|
+
|
|
117
|
+
`v0.3.3` is reliable at surfacing runtime state, correlating errors with HMR activity, detecting common HMR failure patterns, and narrowing `store → render → error` paths in Vue + Pinia workflows.
|
|
118
|
+
|
|
119
|
+
`correlate renders` and `diagnose propagation` are **high-confidence narrowing tools**, not strict causal proof. They intentionally produce conservative output when evidence is incomplete.
|
|
120
|
+
|
|
121
|
+
React store inspection (Zustand, Redux) and deeper cross-framework propagation tracing are on the roadmap.
|
|
122
|
+
|
|
123
|
+
## Development
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
pnpm install
|
|
127
|
+
pnpm build
|
|
128
|
+
pnpm test
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**Requirements:** Node.js ≥ 20 · Chromium via Playwright · Running Vite dev server
|
|
132
|
+
|
|
133
|
+
## License
|
|
134
|
+
|
|
135
|
+
MIT
|
|
@@ -20,7 +20,6 @@ export type BrowserSessionState = {
|
|
|
20
20
|
context: BrowserContext | null;
|
|
21
21
|
page: Page | null;
|
|
22
22
|
framework: BrowserFramework;
|
|
23
|
-
extensionModeDisabled: boolean;
|
|
24
23
|
collectorInstalled: boolean;
|
|
25
24
|
consoleLogs: string[];
|
|
26
25
|
hmrEvents: HmrEvent[];
|
|
@@ -35,3 +34,14 @@ export declare function ensureBrowserPage(state: BrowserSessionState, onPageRead
|
|
|
35
34
|
export declare function closeBrowserSession(state: BrowserSessionState): Promise<void>;
|
|
36
35
|
export declare function contextUsable(current: Pick<BrowserContext, "pages"> | null): current is Pick<BrowserContext, "pages">;
|
|
37
36
|
export declare function isClosedTargetError(error: unknown): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Build platform-aware Chromium launch arguments.
|
|
39
|
+
*
|
|
40
|
+
* On Linux (especially Docker / CI without a display server) we add
|
|
41
|
+
* `--no-sandbox` and `--disable-dev-shm-usage` so that Chromium can
|
|
42
|
+
* start reliably in headless-shell containers.
|
|
43
|
+
*
|
|
44
|
+
* On Windows, `--disable-gpu` is added to work around occasional GPU
|
|
45
|
+
* process crashes on older drivers.
|
|
46
|
+
*/
|
|
47
|
+
export declare function platformChromiumArgs(extra?: string[]): string[];
|
package/dist/browser-session.js
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
-
import { join, resolve } from "node:path";
|
|
3
1
|
import { chromium } from "playwright";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const hasReactExtension = existsSync(join(extensionPath, "manifest.json"));
|
|
7
|
-
const installHook = hasReactExtension
|
|
8
|
-
? readFileSync(join(extensionPath, "build", "installHook.js"), "utf-8")
|
|
9
|
-
: null;
|
|
2
|
+
import { getHookSource } from "./react/hook-manager.js";
|
|
3
|
+
import { isWindows, isLinux } from "./paths.js";
|
|
10
4
|
export function createBrowserSessionState() {
|
|
11
5
|
return {
|
|
12
6
|
context: null,
|
|
13
7
|
page: null,
|
|
14
8
|
framework: "unknown",
|
|
15
|
-
extensionModeDisabled: false,
|
|
16
9
|
collectorInstalled: false,
|
|
17
10
|
consoleLogs: [],
|
|
18
11
|
hmrEvents: [],
|
|
@@ -42,9 +35,7 @@ export function resetBrowserSessionState(state) {
|
|
|
42
35
|
export async function ensureBrowserPage(state, onPageReady) {
|
|
43
36
|
if (!contextUsable(state.context)) {
|
|
44
37
|
await closeBrowserSession(state);
|
|
45
|
-
|
|
46
|
-
state.context = launched.context;
|
|
47
|
-
state.extensionModeDisabled = launched.extensionModeDisabled;
|
|
38
|
+
state.context = await launchBrowserContext();
|
|
48
39
|
}
|
|
49
40
|
if (!state.context)
|
|
50
41
|
throw new Error("browser not open");
|
|
@@ -56,10 +47,7 @@ export async function ensureBrowserPage(state, onPageReady) {
|
|
|
56
47
|
if (!isClosedTargetError(error))
|
|
57
48
|
throw error;
|
|
58
49
|
await closeBrowserSession(state);
|
|
59
|
-
state.
|
|
60
|
-
const launched = await launchBrowserContext(state.extensionModeDisabled);
|
|
61
|
-
state.context = launched.context;
|
|
62
|
-
state.extensionModeDisabled = launched.extensionModeDisabled;
|
|
50
|
+
state.context = await launchBrowserContext();
|
|
63
51
|
state.page = state.context.pages()[0] ?? (await state.context.newPage());
|
|
64
52
|
}
|
|
65
53
|
onPageReady(state.page);
|
|
@@ -86,32 +74,33 @@ export function isClosedTargetError(error) {
|
|
|
86
74
|
return false;
|
|
87
75
|
return /Target page, context or browser has been closed/i.test(error.message);
|
|
88
76
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
extensionModeDisabled = true;
|
|
107
|
-
}
|
|
77
|
+
/**
|
|
78
|
+
* Build platform-aware Chromium launch arguments.
|
|
79
|
+
*
|
|
80
|
+
* On Linux (especially Docker / CI without a display server) we add
|
|
81
|
+
* `--no-sandbox` and `--disable-dev-shm-usage` so that Chromium can
|
|
82
|
+
* start reliably in headless-shell containers.
|
|
83
|
+
*
|
|
84
|
+
* On Windows, `--disable-gpu` is added to work around occasional GPU
|
|
85
|
+
* process crashes on older drivers.
|
|
86
|
+
*/
|
|
87
|
+
export function platformChromiumArgs(extra = []) {
|
|
88
|
+
const args = ["--auto-open-devtools-for-tabs", ...extra];
|
|
89
|
+
if (isLinux) {
|
|
90
|
+
args.push("--no-sandbox", "--disable-dev-shm-usage");
|
|
91
|
+
}
|
|
92
|
+
else if (isWindows) {
|
|
93
|
+
args.push("--disable-gpu");
|
|
108
94
|
}
|
|
95
|
+
return args;
|
|
96
|
+
}
|
|
97
|
+
async function launchBrowserContext() {
|
|
109
98
|
const browser = await chromium.launch({
|
|
110
99
|
headless: false,
|
|
111
|
-
args:
|
|
100
|
+
args: platformChromiumArgs(),
|
|
112
101
|
});
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
102
|
+
const context = await browser.newContext({ viewport: { width: 1280, height: 720 } });
|
|
103
|
+
// Inject bundled React DevTools hook before any page loads
|
|
104
|
+
await context.addInitScript(getHookSource());
|
|
105
|
+
return context;
|
|
117
106
|
}
|
package/dist/browser.d.ts
CHANGED
|
@@ -7,6 +7,17 @@ export { formatHmrTrace, formatModuleGraphSnapshot, formatModuleGraphTrace, form
|
|
|
7
7
|
export type ModuleGraphMode = "snapshot" | "trace" | "clear";
|
|
8
8
|
export declare function setEventQueue(queue: EventQueue): void;
|
|
9
9
|
export declare function getEventQueue(): EventQueue | null;
|
|
10
|
+
export declare function getTrackedHmrEvents(windowMs?: number): Array<{
|
|
11
|
+
timestamp: number;
|
|
12
|
+
type: "hmr-update" | "hmr-error";
|
|
13
|
+
payload: {
|
|
14
|
+
path?: string;
|
|
15
|
+
message?: string;
|
|
16
|
+
updates?: Array<{
|
|
17
|
+
path?: string;
|
|
18
|
+
}>;
|
|
19
|
+
};
|
|
20
|
+
}>;
|
|
10
21
|
export declare function getCurrentPage(): Page | null;
|
|
11
22
|
/**
|
|
12
23
|
* Flush browser events into daemon event queue
|