e2e-pilot 0.0.69

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 (152) hide show
  1. package/bin.js +3 -0
  2. package/dist/aria-snapshot.d.ts +95 -0
  3. package/dist/aria-snapshot.d.ts.map +1 -0
  4. package/dist/aria-snapshot.js +490 -0
  5. package/dist/aria-snapshot.js.map +1 -0
  6. package/dist/bippy.js +971 -0
  7. package/dist/cdp-relay.d.ts +16 -0
  8. package/dist/cdp-relay.d.ts.map +1 -0
  9. package/dist/cdp-relay.js +715 -0
  10. package/dist/cdp-relay.js.map +1 -0
  11. package/dist/cdp-session.d.ts +42 -0
  12. package/dist/cdp-session.d.ts.map +1 -0
  13. package/dist/cdp-session.js +154 -0
  14. package/dist/cdp-session.js.map +1 -0
  15. package/dist/cdp-types.d.ts +63 -0
  16. package/dist/cdp-types.d.ts.map +1 -0
  17. package/dist/cdp-types.js +91 -0
  18. package/dist/cdp-types.js.map +1 -0
  19. package/dist/cli.d.ts +3 -0
  20. package/dist/cli.d.ts.map +1 -0
  21. package/dist/cli.js +213 -0
  22. package/dist/cli.js.map +1 -0
  23. package/dist/create-logger.d.ts +9 -0
  24. package/dist/create-logger.d.ts.map +1 -0
  25. package/dist/create-logger.js +25 -0
  26. package/dist/create-logger.js.map +1 -0
  27. package/dist/debugger-api.md +458 -0
  28. package/dist/debugger-examples-types.d.ts +24 -0
  29. package/dist/debugger-examples-types.d.ts.map +1 -0
  30. package/dist/debugger-examples-types.js +2 -0
  31. package/dist/debugger-examples-types.js.map +1 -0
  32. package/dist/debugger-examples.d.ts +6 -0
  33. package/dist/debugger-examples.d.ts.map +1 -0
  34. package/dist/debugger-examples.js +53 -0
  35. package/dist/debugger-examples.js.map +1 -0
  36. package/dist/debugger.d.ts +381 -0
  37. package/dist/debugger.d.ts.map +1 -0
  38. package/dist/debugger.js +633 -0
  39. package/dist/debugger.js.map +1 -0
  40. package/dist/editor-api.md +364 -0
  41. package/dist/editor-examples.d.ts +11 -0
  42. package/dist/editor-examples.d.ts.map +1 -0
  43. package/dist/editor-examples.js +124 -0
  44. package/dist/editor-examples.js.map +1 -0
  45. package/dist/editor.d.ts +203 -0
  46. package/dist/editor.d.ts.map +1 -0
  47. package/dist/editor.js +336 -0
  48. package/dist/editor.js.map +1 -0
  49. package/dist/execute.d.ts +50 -0
  50. package/dist/execute.d.ts.map +1 -0
  51. package/dist/execute.js +576 -0
  52. package/dist/execute.js.map +1 -0
  53. package/dist/index.d.ts +11 -0
  54. package/dist/index.d.ts.map +1 -0
  55. package/dist/index.js +7 -0
  56. package/dist/index.js.map +1 -0
  57. package/dist/mcp-client.d.ts +20 -0
  58. package/dist/mcp-client.d.ts.map +1 -0
  59. package/dist/mcp-client.js +56 -0
  60. package/dist/mcp-client.js.map +1 -0
  61. package/dist/mcp.d.ts +5 -0
  62. package/dist/mcp.d.ts.map +1 -0
  63. package/dist/mcp.js +720 -0
  64. package/dist/mcp.js.map +1 -0
  65. package/dist/mcp.test.d.ts +10 -0
  66. package/dist/mcp.test.d.ts.map +1 -0
  67. package/dist/mcp.test.js +2999 -0
  68. package/dist/mcp.test.js.map +1 -0
  69. package/dist/network-capture.d.ts +23 -0
  70. package/dist/network-capture.d.ts.map +1 -0
  71. package/dist/network-capture.js +98 -0
  72. package/dist/network-capture.js.map +1 -0
  73. package/dist/protocol.d.ts +54 -0
  74. package/dist/protocol.d.ts.map +1 -0
  75. package/dist/protocol.js +2 -0
  76. package/dist/protocol.js.map +1 -0
  77. package/dist/react-source.d.ts +13 -0
  78. package/dist/react-source.d.ts.map +1 -0
  79. package/dist/react-source.js +68 -0
  80. package/dist/react-source.js.map +1 -0
  81. package/dist/scoped-fs.d.ts +94 -0
  82. package/dist/scoped-fs.d.ts.map +1 -0
  83. package/dist/scoped-fs.js +356 -0
  84. package/dist/scoped-fs.js.map +1 -0
  85. package/dist/selector-generator.js +8126 -0
  86. package/dist/start-relay-server.d.ts +6 -0
  87. package/dist/start-relay-server.d.ts.map +1 -0
  88. package/dist/start-relay-server.js +33 -0
  89. package/dist/start-relay-server.js.map +1 -0
  90. package/dist/styles-api.md +117 -0
  91. package/dist/styles-examples.d.ts +8 -0
  92. package/dist/styles-examples.d.ts.map +1 -0
  93. package/dist/styles-examples.js +64 -0
  94. package/dist/styles-examples.js.map +1 -0
  95. package/dist/styles.d.ts +27 -0
  96. package/dist/styles.d.ts.map +1 -0
  97. package/dist/styles.js +234 -0
  98. package/dist/styles.js.map +1 -0
  99. package/dist/trace-utils.d.ts +14 -0
  100. package/dist/trace-utils.d.ts.map +1 -0
  101. package/dist/trace-utils.js +21 -0
  102. package/dist/trace-utils.js.map +1 -0
  103. package/dist/utils.d.ts +20 -0
  104. package/dist/utils.d.ts.map +1 -0
  105. package/dist/utils.js +75 -0
  106. package/dist/utils.js.map +1 -0
  107. package/dist/wait-for-page-load.d.ts +16 -0
  108. package/dist/wait-for-page-load.d.ts.map +1 -0
  109. package/dist/wait-for-page-load.js +127 -0
  110. package/dist/wait-for-page-load.js.map +1 -0
  111. package/package.json +67 -0
  112. package/src/aria-snapshot.ts +610 -0
  113. package/src/assets/aria-labels-github-snapshot.txt +605 -0
  114. package/src/assets/aria-labels-github.png +0 -0
  115. package/src/assets/aria-labels-google-snapshot.txt +49 -0
  116. package/src/assets/aria-labels-google.png +0 -0
  117. package/src/assets/aria-labels-hacker-news-snapshot.txt +1023 -0
  118. package/src/assets/aria-labels-hacker-news.png +0 -0
  119. package/src/cdp-relay.ts +925 -0
  120. package/src/cdp-session.ts +203 -0
  121. package/src/cdp-timing.md +128 -0
  122. package/src/cdp-types.ts +155 -0
  123. package/src/cli.ts +250 -0
  124. package/src/create-logger.ts +36 -0
  125. package/src/debugger-examples-types.ts +13 -0
  126. package/src/debugger-examples.ts +66 -0
  127. package/src/debugger.md +453 -0
  128. package/src/debugger.ts +713 -0
  129. package/src/editor-examples.ts +148 -0
  130. package/src/editor.ts +390 -0
  131. package/src/execute.ts +763 -0
  132. package/src/index.ts +10 -0
  133. package/src/mcp-client.ts +78 -0
  134. package/src/mcp.test.ts +3596 -0
  135. package/src/mcp.ts +876 -0
  136. package/src/network-capture.ts +140 -0
  137. package/src/prompt.bak.md +323 -0
  138. package/src/prompt.md +7 -0
  139. package/src/protocol.ts +63 -0
  140. package/src/react-source.ts +94 -0
  141. package/src/resource.md +436 -0
  142. package/src/scoped-fs.ts +411 -0
  143. package/src/snapshots/hacker-news-focused-accessibility.md +202 -0
  144. package/src/snapshots/hacker-news-initial-accessibility.md +11 -0
  145. package/src/snapshots/hacker-news-tabbed-accessibility.md +202 -0
  146. package/src/snapshots/shadcn-ui-accessibility.md +11 -0
  147. package/src/start-relay-server.ts +43 -0
  148. package/src/styles-examples.ts +77 -0
  149. package/src/styles.ts +345 -0
  150. package/src/trace-utils.ts +43 -0
  151. package/src/utils.ts +91 -0
  152. package/src/wait-for-page-load.ts +174 -0
@@ -0,0 +1,713 @@
1
+ import type { ICDPSession, CDPSession } from './cdp-session.js'
2
+ import type { Protocol } from 'devtools-protocol'
3
+
4
+ export interface BreakpointInfo {
5
+ id: string
6
+ file: string
7
+ line: number
8
+ }
9
+
10
+ export interface LocationInfo {
11
+ url: string
12
+ lineNumber: number
13
+ columnNumber: number
14
+ callstack: Array<{
15
+ functionName: string
16
+ url: string
17
+ lineNumber: number
18
+ columnNumber: number
19
+ }>
20
+ sourceContext: string
21
+ }
22
+
23
+ export interface EvaluateResult {
24
+ value: unknown
25
+ }
26
+
27
+
28
+
29
+ export interface ScriptInfo {
30
+ scriptId: string
31
+ url: string
32
+ }
33
+
34
+ /**
35
+ * A class for debugging JavaScript code via Chrome DevTools Protocol.
36
+ * Works with both Node.js (--inspect) and browser debugging.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * const cdp = await getCDPSessionForPage({ page, wsUrl })
41
+ * const dbg = new Debugger({ cdp })
42
+ *
43
+ * await dbg.setBreakpoint({ file: 'https://example.com/app.js', line: 42 })
44
+ * // trigger the code path, then:
45
+ * const location = await dbg.getLocation()
46
+ * const vars = await dbg.inspectLocalVariables()
47
+ * await dbg.resume()
48
+ * ```
49
+ */
50
+ export class Debugger {
51
+ private cdp: CDPSession
52
+ private debuggerEnabled = false
53
+ private paused = false
54
+ private currentCallFrames: Protocol.Debugger.CallFrame[] = []
55
+ private breakpoints = new Map<string, BreakpointInfo>()
56
+ private scripts = new Map<string, ScriptInfo>()
57
+ private xhrBreakpoints = new Set<string>()
58
+ private blackboxPatterns: string[] = []
59
+
60
+ /**
61
+ * Creates a new Debugger instance.
62
+ *
63
+ * @param options - Configuration options
64
+ * @param options.cdp - A CDPSession instance for sending CDP commands (works with both
65
+ * our CDPSession and Playwright's CDPSession)
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * const cdp = await getCDPSessionForPage({ page, wsUrl })
70
+ * const dbg = new Debugger({ cdp })
71
+ * ```
72
+ */
73
+ constructor({ cdp }: { cdp: ICDPSession }) {
74
+ // Cast to CDPSession for internal type safety - at runtime both are compatible
75
+ this.cdp = cdp as CDPSession
76
+ this.setupEventListeners()
77
+ }
78
+
79
+ private setupEventListeners() {
80
+ this.cdp.on('Debugger.paused', (params) => {
81
+ this.paused = true
82
+ this.currentCallFrames = params.callFrames
83
+ })
84
+
85
+ this.cdp.on('Debugger.resumed', () => {
86
+ this.paused = false
87
+ this.currentCallFrames = []
88
+ })
89
+
90
+ this.cdp.on('Debugger.scriptParsed', (params) => {
91
+ if (params.url && !params.url.startsWith('chrome') && !params.url.startsWith('devtools')) {
92
+ this.scripts.set(params.scriptId, {
93
+ scriptId: params.scriptId,
94
+ url: params.url,
95
+ })
96
+ }
97
+ })
98
+ }
99
+
100
+ /**
101
+ * Enables the debugger and runtime domains. Called automatically by other methods.
102
+ * Also resumes execution if the target was started with --inspect-brk.
103
+ *
104
+ * @example
105
+ * ```ts
106
+ * await dbg.enable()
107
+ * ```
108
+ */
109
+ async enable(): Promise<void> {
110
+ if (this.debuggerEnabled) {
111
+ return
112
+ }
113
+ await this.cdp.send('Debugger.disable')
114
+ await this.cdp.send('Runtime.disable')
115
+ this.scripts.clear()
116
+ const scriptsReady = new Promise<void>((resolve) => {
117
+ let timeout: ReturnType<typeof setTimeout>
118
+ const listener = () => {
119
+ clearTimeout(timeout)
120
+ timeout = setTimeout(() => {
121
+ this.cdp.off('Debugger.scriptParsed', listener)
122
+ resolve()
123
+ }, 100)
124
+ }
125
+ this.cdp.on('Debugger.scriptParsed', listener)
126
+ timeout = setTimeout(() => {
127
+ this.cdp.off('Debugger.scriptParsed', listener)
128
+ resolve()
129
+ }, 100)
130
+ })
131
+ await this.cdp.send('Debugger.enable')
132
+ await this.cdp.send('Runtime.enable')
133
+ await this.cdp.send('Runtime.runIfWaitingForDebugger')
134
+ await scriptsReady
135
+ this.debuggerEnabled = true
136
+ }
137
+
138
+ /**
139
+ * Sets a breakpoint at a specified URL and line number.
140
+ * Use the URL from listScripts() to find available scripts.
141
+ *
142
+ * @param options - Breakpoint options
143
+ * @param options.file - Script URL (e.g. https://example.com/app.js)
144
+ * @param options.line - Line number (1-based)
145
+ * @param options.condition - Optional JS expression; only pause when it evaluates to true
146
+ * @returns The breakpoint ID for later removal
147
+ *
148
+ * @example
149
+ * ```ts
150
+ * const id = await dbg.setBreakpoint({ file: 'https://example.com/app.js', line: 42 })
151
+ * // later:
152
+ * await dbg.deleteBreakpoint({ breakpointId: id })
153
+ *
154
+ * // Conditional breakpoint - only pause when userId is 123
155
+ * await dbg.setBreakpoint({
156
+ * file: 'https://example.com/app.js',
157
+ * line: 42,
158
+ * condition: 'userId === 123'
159
+ * })
160
+ * ```
161
+ */
162
+ async setBreakpoint({ file, line, condition }: { file: string; line: number; condition?: string }): Promise<string> {
163
+ await this.enable()
164
+
165
+ const response = await this.cdp.send('Debugger.setBreakpointByUrl', {
166
+ lineNumber: line - 1,
167
+ urlRegex: file.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'),
168
+ columnNumber: 0,
169
+ condition,
170
+ })
171
+
172
+ this.breakpoints.set(response.breakpointId, { id: response.breakpointId, file, line })
173
+ return response.breakpointId
174
+ }
175
+
176
+ /**
177
+ * Removes a breakpoint by its ID.
178
+ *
179
+ * @param options - Options
180
+ * @param options.breakpointId - The breakpoint ID returned by setBreakpoint
181
+ *
182
+ * @example
183
+ * ```ts
184
+ * await dbg.deleteBreakpoint({ breakpointId: 'bp-123' })
185
+ * ```
186
+ */
187
+ async deleteBreakpoint({ breakpointId }: { breakpointId: string }): Promise<void> {
188
+ await this.enable()
189
+ await this.cdp.send('Debugger.removeBreakpoint', { breakpointId })
190
+ this.breakpoints.delete(breakpointId)
191
+ }
192
+
193
+ /**
194
+ * Returns a list of all active breakpoints set by this debugger instance.
195
+ *
196
+ * @returns Array of breakpoint info objects
197
+ *
198
+ * @example
199
+ * ```ts
200
+ * const breakpoints = dbg.listBreakpoints()
201
+ * // [{ id: 'bp-123', file: 'https://example.com/index.js', line: 42 }]
202
+ * ```
203
+ */
204
+ listBreakpoints(): BreakpointInfo[] {
205
+ return Array.from(this.breakpoints.values())
206
+ }
207
+
208
+ /**
209
+ * Inspects local variables in the current call frame.
210
+ * Must be paused at a breakpoint. String values over 1000 chars are truncated.
211
+ * Use evaluate() for full control over reading specific values.
212
+ *
213
+ * @returns Record of variable names to values
214
+ * @throws Error if not paused or no active call frames
215
+ *
216
+ * @example
217
+ * ```ts
218
+ * const vars = await dbg.inspectLocalVariables()
219
+ * // { myVar: 'hello', count: 42 }
220
+ * ```
221
+ */
222
+ async inspectLocalVariables(): Promise<Record<string, unknown>> {
223
+ await this.enable()
224
+
225
+ if (!this.paused || this.currentCallFrames.length === 0) {
226
+ throw new Error('Debugger is not paused at a breakpoint')
227
+ }
228
+
229
+ const frame = this.currentCallFrames[0]
230
+ const result: Record<string, unknown> = {}
231
+
232
+ for (const scopeObj of frame.scopeChain) {
233
+ if (scopeObj.type === 'global') {
234
+ continue
235
+ }
236
+
237
+ if (!scopeObj.object.objectId) {
238
+ continue
239
+ }
240
+
241
+ const objProperties = await this.cdp.send('Runtime.getProperties', {
242
+ objectId: scopeObj.object.objectId,
243
+ ownProperties: true,
244
+ accessorPropertiesOnly: false,
245
+ generatePreview: true,
246
+ })
247
+
248
+ for (const prop of objProperties.result) {
249
+ if (prop.value && prop.configurable) {
250
+ result[prop.name] = this.formatPropertyValue(prop.value)
251
+ }
252
+ }
253
+ }
254
+
255
+ return result
256
+ }
257
+
258
+ /**
259
+ * Returns global lexical scope variable names.
260
+ *
261
+ * @returns Array of global variable names
262
+ *
263
+ * @example
264
+ * ```ts
265
+ * const globals = await dbg.inspectGlobalVariables()
266
+ * // ['myGlobal', 'CONFIG']
267
+ * ```
268
+ */
269
+ async inspectGlobalVariables(): Promise<string[]> {
270
+ await this.enable()
271
+
272
+ const response = await this.cdp.send('Runtime.globalLexicalScopeNames', {})
273
+
274
+ return response.names
275
+ }
276
+
277
+ /**
278
+ * Evaluates a JavaScript expression and returns the result.
279
+ * When paused at a breakpoint, evaluates in the current stack frame scope,
280
+ * allowing access to local variables. Otherwise evaluates in global scope.
281
+ * Values are not truncated, use this for full control over reading specific variables.
282
+ *
283
+ * @param options - Options
284
+ * @param options.expression - JavaScript expression to evaluate
285
+ * @returns The result value
286
+ *
287
+ * @example
288
+ * ```ts
289
+ * // When paused, can access local variables:
290
+ * const result = await dbg.evaluate({ expression: 'localVar + 1' })
291
+ *
292
+ * // Read a large string that would be truncated in inspectLocalVariables:
293
+ * const full = await dbg.evaluate({ expression: 'largeStringVar' })
294
+ * ```
295
+ */
296
+ async evaluate({ expression }: { expression: string }): Promise<EvaluateResult> {
297
+ await this.enable()
298
+
299
+ const wrappedExpression = `
300
+ try {
301
+ ${expression}
302
+ } catch (e) {
303
+ e;
304
+ }
305
+ `
306
+
307
+ let response: Protocol.Debugger.EvaluateOnCallFrameResponse | Protocol.Runtime.EvaluateResponse
308
+
309
+ if (this.paused && this.currentCallFrames.length > 0) {
310
+ const frame = this.currentCallFrames[0]
311
+ response = await this.cdp.send('Debugger.evaluateOnCallFrame', {
312
+ callFrameId: frame.callFrameId,
313
+ expression: wrappedExpression,
314
+ objectGroup: 'console',
315
+ includeCommandLineAPI: true,
316
+ silent: false,
317
+ returnByValue: true,
318
+ generatePreview: true,
319
+ })
320
+ } else {
321
+ response = await this.cdp.send('Runtime.evaluate', {
322
+ expression: wrappedExpression,
323
+ objectGroup: 'console',
324
+ includeCommandLineAPI: true,
325
+ silent: false,
326
+ returnByValue: true,
327
+ generatePreview: true,
328
+ awaitPromise: true,
329
+ })
330
+ }
331
+
332
+ const value = await this.processRemoteObject(response.result)
333
+
334
+ return { value }
335
+ }
336
+
337
+ /**
338
+ * Gets the current execution location when paused at a breakpoint.
339
+ * Includes the call stack and surrounding source code for context.
340
+ *
341
+ * @returns Location info with URL, line number, call stack, and source context
342
+ * @throws Error if debugger is not paused
343
+ *
344
+ * @example
345
+ * ```ts
346
+ * const location = await dbg.getLocation()
347
+ * console.log(location.url) // 'https://example.com/src/index.js'
348
+ * console.log(location.lineNumber) // 42
349
+ * console.log(location.callstack) // [{ functionName: 'handleRequest', ... }]
350
+ * console.log(location.sourceContext)
351
+ * // ' 40: function handleRequest(req) {
352
+ * // 41: const data = req.body
353
+ * // > 42: processData(data)
354
+ * // 43: }'
355
+ * ```
356
+ */
357
+ async getLocation(): Promise<LocationInfo> {
358
+ await this.enable()
359
+
360
+ if (!this.paused || this.currentCallFrames.length === 0) {
361
+ throw new Error('Debugger is not paused at a breakpoint')
362
+ }
363
+
364
+ const frame = this.currentCallFrames[0]
365
+ const { scriptId, lineNumber, columnNumber } = frame.location
366
+
367
+ const callstack = this.currentCallFrames.map((f) => ({
368
+ functionName: f.functionName || '(anonymous)',
369
+ url: f.url,
370
+ lineNumber: f.location.lineNumber + 1,
371
+ columnNumber: f.location.columnNumber || 0,
372
+ }))
373
+
374
+ let sourceContext = ''
375
+ try {
376
+ const scriptSource = await this.cdp.send('Debugger.getScriptSource', { scriptId })
377
+ const lines = scriptSource.scriptSource.split('\n')
378
+ const startLine = Math.max(0, lineNumber - 3)
379
+ const endLine = Math.min(lines.length - 1, lineNumber + 3)
380
+
381
+ for (let i = startLine; i <= endLine; i++) {
382
+ const prefix = i === lineNumber ? '> ' : ' '
383
+ sourceContext += `${prefix}${i + 1}: ${lines[i]}\n`
384
+ }
385
+ } catch {
386
+ sourceContext = 'Unable to retrieve source code'
387
+ }
388
+
389
+ return {
390
+ url: frame.url,
391
+ lineNumber: lineNumber + 1,
392
+ columnNumber: columnNumber || 0,
393
+ callstack,
394
+ sourceContext,
395
+ }
396
+ }
397
+
398
+ /**
399
+ * Steps over to the next line of code, not entering function calls.
400
+ *
401
+ * @throws Error if debugger is not paused
402
+ *
403
+ * @example
404
+ * ```ts
405
+ * await dbg.stepOver()
406
+ * const newLocation = await dbg.getLocation()
407
+ * ```
408
+ */
409
+ async stepOver(): Promise<void> {
410
+ await this.enable()
411
+ if (!this.paused) {
412
+ throw new Error('Debugger is not paused')
413
+ }
414
+ await this.cdp.send('Debugger.stepOver')
415
+ }
416
+
417
+ /**
418
+ * Steps into a function call on the current line.
419
+ *
420
+ * @throws Error if debugger is not paused
421
+ *
422
+ * @example
423
+ * ```ts
424
+ * await dbg.stepInto()
425
+ * const location = await dbg.getLocation()
426
+ * // now inside the called function
427
+ * ```
428
+ */
429
+ async stepInto(): Promise<void> {
430
+ await this.enable()
431
+ if (!this.paused) {
432
+ throw new Error('Debugger is not paused')
433
+ }
434
+ await this.cdp.send('Debugger.stepInto')
435
+ }
436
+
437
+ /**
438
+ * Steps out of the current function, returning to the caller.
439
+ *
440
+ * @throws Error if debugger is not paused
441
+ *
442
+ * @example
443
+ * ```ts
444
+ * await dbg.stepOut()
445
+ * const location = await dbg.getLocation()
446
+ * // back in the calling function
447
+ * ```
448
+ */
449
+ async stepOut(): Promise<void> {
450
+ await this.enable()
451
+ if (!this.paused) {
452
+ throw new Error('Debugger is not paused')
453
+ }
454
+ await this.cdp.send('Debugger.stepOut')
455
+ }
456
+
457
+ /**
458
+ * Resumes code execution until the next breakpoint or completion.
459
+ *
460
+ * @throws Error if debugger is not paused
461
+ *
462
+ * @example
463
+ * ```ts
464
+ * await dbg.resume()
465
+ * // execution continues
466
+ * ```
467
+ */
468
+ async resume(): Promise<void> {
469
+ await this.enable()
470
+ if (!this.paused) {
471
+ throw new Error('Debugger is not paused')
472
+ }
473
+ await this.cdp.send('Debugger.resume')
474
+ }
475
+
476
+ /**
477
+ * Returns whether the debugger is currently paused at a breakpoint.
478
+ *
479
+ * @returns true if paused, false otherwise
480
+ *
481
+ * @example
482
+ * ```ts
483
+ * if (dbg.isPaused()) {
484
+ * const vars = await dbg.inspectLocalVariables()
485
+ * }
486
+ * ```
487
+ */
488
+ isPaused(): boolean {
489
+ return this.paused
490
+ }
491
+
492
+ /**
493
+ * Configures the debugger to pause on exceptions.
494
+ *
495
+ * @param options - Options
496
+ * @param options.state - When to pause: 'none' (never), 'uncaught' (only uncaught), or 'all' (all exceptions)
497
+ *
498
+ * @example
499
+ * ```ts
500
+ * // Pause only on uncaught exceptions
501
+ * await dbg.setPauseOnExceptions({ state: 'uncaught' })
502
+ *
503
+ * // Pause on all exceptions (caught and uncaught)
504
+ * await dbg.setPauseOnExceptions({ state: 'all' })
505
+ *
506
+ * // Disable pausing on exceptions
507
+ * await dbg.setPauseOnExceptions({ state: 'none' })
508
+ * ```
509
+ */
510
+ async setPauseOnExceptions({ state }: { state: 'none' | 'uncaught' | 'all' }): Promise<void> {
511
+ await this.enable()
512
+ await this.cdp.send('Debugger.setPauseOnExceptions', { state })
513
+ }
514
+
515
+ /**
516
+ * Lists available scripts where breakpoints can be set.
517
+ * Automatically enables the debugger if not already enabled.
518
+ *
519
+ * @param options - Options
520
+ * @param options.search - Optional string to filter scripts by URL (case-insensitive)
521
+ * @returns Array of up to 20 matching scripts with scriptId and url
522
+ *
523
+ * @example
524
+ * ```ts
525
+ * // List all scripts
526
+ * const scripts = await dbg.listScripts()
527
+ * // [{ scriptId: '1', url: 'https://example.com/app.js' }, ...]
528
+ *
529
+ * // Search for specific files
530
+ * const handlers = await dbg.listScripts({ search: 'handler' })
531
+ * // [{ scriptId: '5', url: 'https://example.com/handlers.js' }]
532
+ * ```
533
+ */
534
+ async listScripts({ search }: { search?: string } = {}): Promise<ScriptInfo[]> {
535
+ await this.enable()
536
+ const scripts = Array.from(this.scripts.values())
537
+ const filtered = search
538
+ ? scripts.filter((s) => s.url.toLowerCase().includes(search.toLowerCase()))
539
+ : scripts
540
+ return filtered.slice(0, 20)
541
+ }
542
+
543
+ async setXHRBreakpoint({ url }: { url: string }): Promise<void> {
544
+ await this.enable()
545
+ await this.cdp.send('DOMDebugger.setXHRBreakpoint', { url })
546
+ this.xhrBreakpoints.add(url)
547
+ }
548
+
549
+ async removeXHRBreakpoint({ url }: { url: string }): Promise<void> {
550
+ await this.enable()
551
+ await this.cdp.send('DOMDebugger.removeXHRBreakpoint', { url })
552
+ this.xhrBreakpoints.delete(url)
553
+ }
554
+
555
+ listXHRBreakpoints(): string[] {
556
+ return Array.from(this.xhrBreakpoints)
557
+ }
558
+
559
+ /**
560
+ * Sets regex patterns for scripts to blackbox (skip when stepping).
561
+ * Blackboxed scripts are hidden from the call stack and stepped over automatically.
562
+ * Useful for ignoring framework/library code during debugging.
563
+ *
564
+ * @param options - Options
565
+ * @param options.patterns - Array of regex patterns to match script URLs
566
+ *
567
+ * @example
568
+ * ```ts
569
+ * // Skip all node_modules
570
+ * await dbg.setBlackboxPatterns({ patterns: ['node_modules'] })
571
+ *
572
+ * // Skip React and other frameworks
573
+ * await dbg.setBlackboxPatterns({
574
+ * patterns: [
575
+ * 'node_modules/react',
576
+ * 'node_modules/react-dom',
577
+ * 'node_modules/next',
578
+ * 'webpack://',
579
+ * ]
580
+ * })
581
+ *
582
+ * // Skip all third-party scripts
583
+ * await dbg.setBlackboxPatterns({ patterns: ['^https://cdn\\.'] })
584
+ *
585
+ * // Clear all blackbox patterns
586
+ * await dbg.setBlackboxPatterns({ patterns: [] })
587
+ * ```
588
+ */
589
+ async setBlackboxPatterns({ patterns }: { patterns: string[] }): Promise<void> {
590
+ await this.enable()
591
+ this.blackboxPatterns = patterns
592
+ await this.cdp.send('Debugger.setBlackboxPatterns', { patterns })
593
+ }
594
+
595
+ /**
596
+ * Adds a single regex pattern to the blackbox list.
597
+ *
598
+ * @param options - Options
599
+ * @param options.pattern - Regex pattern to match script URLs
600
+ *
601
+ * @example
602
+ * ```ts
603
+ * await dbg.addBlackboxPattern({ pattern: 'node_modules/lodash' })
604
+ * await dbg.addBlackboxPattern({ pattern: 'node_modules/axios' })
605
+ * ```
606
+ */
607
+ async addBlackboxPattern({ pattern }: { pattern: string }): Promise<void> {
608
+ await this.enable()
609
+ if (!this.blackboxPatterns.includes(pattern)) {
610
+ this.blackboxPatterns.push(pattern)
611
+ await this.cdp.send('Debugger.setBlackboxPatterns', { patterns: this.blackboxPatterns })
612
+ }
613
+ }
614
+
615
+ /**
616
+ * Removes a pattern from the blackbox list.
617
+ *
618
+ * @param options - Options
619
+ * @param options.pattern - The exact pattern string to remove
620
+ */
621
+ async removeBlackboxPattern({ pattern }: { pattern: string }): Promise<void> {
622
+ await this.enable()
623
+ this.blackboxPatterns = this.blackboxPatterns.filter((p) => p !== pattern)
624
+ await this.cdp.send('Debugger.setBlackboxPatterns', { patterns: this.blackboxPatterns })
625
+ }
626
+
627
+ /**
628
+ * Returns the current list of blackbox patterns.
629
+ */
630
+ listBlackboxPatterns(): string[] {
631
+ return [...this.blackboxPatterns]
632
+ }
633
+
634
+ private truncateValue(value: unknown): unknown {
635
+ if (typeof value === 'string' && value.length > 1000) {
636
+ return value.slice(0, 1000) + `... (${value.length} chars)`
637
+ }
638
+ return value
639
+ }
640
+
641
+ private formatPropertyValue(value: Protocol.Runtime.RemoteObject): unknown {
642
+ if (value.type === 'object' && value.subtype !== 'null') {
643
+ return `[${value.subtype || value.type}]`
644
+ }
645
+ if (value.type === 'function') {
646
+ return '[function]'
647
+ }
648
+ if (value.value !== undefined) {
649
+ return this.truncateValue(value.value)
650
+ }
651
+ return `[${value.type}]`
652
+ }
653
+
654
+ private async processRemoteObject(obj: Protocol.Runtime.RemoteObject): Promise<unknown> {
655
+ if (obj.type === 'undefined') {
656
+ return undefined
657
+ }
658
+
659
+ if (obj.value !== undefined) {
660
+ return obj.value
661
+ }
662
+
663
+ if (obj.type === 'object' && obj.objectId) {
664
+ try {
665
+ const props = await this.cdp.send('Runtime.getProperties', {
666
+ objectId: obj.objectId,
667
+ ownProperties: true,
668
+ accessorPropertiesOnly: false,
669
+ generatePreview: true,
670
+ })
671
+
672
+ const result: Record<string, unknown> = {}
673
+ for (const prop of props.result) {
674
+ if (prop.value) {
675
+ if (prop.value.type === 'object' && prop.value.objectId && prop.value.subtype !== 'null') {
676
+ try {
677
+ const nestedProps = await this.cdp.send('Runtime.getProperties', {
678
+ objectId: prop.value.objectId,
679
+ ownProperties: true,
680
+ accessorPropertiesOnly: false,
681
+ generatePreview: true,
682
+ })
683
+ const nestedObj: Record<string, unknown> = {}
684
+ for (const nestedProp of nestedProps.result) {
685
+ if (nestedProp.value) {
686
+ nestedObj[nestedProp.name] =
687
+ nestedProp.value.value !== undefined
688
+ ? nestedProp.value.value
689
+ : nestedProp.value.description || `[${nestedProp.value.subtype || nestedProp.value.type}]`
690
+ }
691
+ }
692
+ result[prop.name] = nestedObj
693
+ } catch {
694
+ result[prop.name] = prop.value.description || `[${prop.value.subtype || prop.value.type}]`
695
+ }
696
+ } else if (prop.value.type === 'function') {
697
+ result[prop.name] = '[function]'
698
+ } else if (prop.value.value !== undefined) {
699
+ result[prop.name] = prop.value.value
700
+ } else {
701
+ result[prop.name] = `[${prop.value.type}]`
702
+ }
703
+ }
704
+ }
705
+ return result
706
+ } catch {
707
+ return obj.description || `[${obj.subtype || obj.type}]`
708
+ }
709
+ }
710
+
711
+ return obj.description || `[${obj.type}]`
712
+ }
713
+ }