playwriter 0.0.30 → 0.0.33

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.
@@ -0,0 +1,457 @@
1
+ # Debugger API Reference
2
+
3
+ ## Types
4
+
5
+ ```ts
6
+ import type { CDPSession } from './cdp-session.js';
7
+ export interface BreakpointInfo {
8
+ id: string;
9
+ file: string;
10
+ line: number;
11
+ }
12
+ export interface LocationInfo {
13
+ url: string;
14
+ lineNumber: number;
15
+ columnNumber: number;
16
+ callstack: Array<{
17
+ functionName: string;
18
+ url: string;
19
+ lineNumber: number;
20
+ columnNumber: number;
21
+ }>;
22
+ sourceContext: string;
23
+ }
24
+ export interface EvaluateResult {
25
+ value: unknown;
26
+ }
27
+ export interface ScriptInfo {
28
+ scriptId: string;
29
+ url: string;
30
+ }
31
+ /**
32
+ * A class for debugging JavaScript code via Chrome DevTools Protocol.
33
+ * Works with both Node.js (--inspect) and browser debugging.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * const cdp = await getCDPSessionForPage({ page, wsUrl })
38
+ * const dbg = new Debugger({ cdp })
39
+ *
40
+ * await dbg.setBreakpoint({ file: 'https://example.com/app.js', line: 42 })
41
+ * // trigger the code path, then:
42
+ * const location = await dbg.getLocation()
43
+ * const vars = await dbg.inspectLocalVariables()
44
+ * await dbg.resume()
45
+ * ```
46
+ */
47
+ export declare class Debugger {
48
+ private cdp;
49
+ private debuggerEnabled;
50
+ private paused;
51
+ private currentCallFrames;
52
+ private breakpoints;
53
+ private scripts;
54
+ private xhrBreakpoints;
55
+ private blackboxPatterns;
56
+ /**
57
+ * Creates a new Debugger instance.
58
+ *
59
+ * @param options - Configuration options
60
+ * @param options.cdp - A CDPSession instance for sending CDP commands
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * const cdp = await getCDPSessionForPage({ page, wsUrl })
65
+ * const dbg = new Debugger({ cdp })
66
+ * ```
67
+ */
68
+ constructor({ cdp }: {
69
+ cdp: CDPSession;
70
+ });
71
+ private setupEventListeners;
72
+ /**
73
+ * Enables the debugger and runtime domains. Called automatically by other methods.
74
+ * Also resumes execution if the target was started with --inspect-brk.
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * await dbg.enable()
79
+ * ```
80
+ */
81
+ enable(): Promise<void>;
82
+ /**
83
+ * Sets a breakpoint at a specified URL and line number.
84
+ * Use the URL from listScripts() to find available scripts.
85
+ *
86
+ * @param options - Breakpoint options
87
+ * @param options.file - Script URL (e.g. https://example.com/app.js)
88
+ * @param options.line - Line number (1-based)
89
+ * @param options.condition - Optional JS expression; only pause when it evaluates to true
90
+ * @returns The breakpoint ID for later removal
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * const id = await dbg.setBreakpoint({ file: 'https://example.com/app.js', line: 42 })
95
+ * // later:
96
+ * await dbg.deleteBreakpoint({ breakpointId: id })
97
+ *
98
+ * // Conditional breakpoint - only pause when userId is 123
99
+ * await dbg.setBreakpoint({
100
+ * file: 'https://example.com/app.js',
101
+ * line: 42,
102
+ * condition: 'userId === 123'
103
+ * })
104
+ * ```
105
+ */
106
+ setBreakpoint({ file, line, condition }: {
107
+ file: string;
108
+ line: number;
109
+ condition?: string;
110
+ }): Promise<string>;
111
+ /**
112
+ * Removes a breakpoint by its ID.
113
+ *
114
+ * @param options - Options
115
+ * @param options.breakpointId - The breakpoint ID returned by setBreakpoint
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * await dbg.deleteBreakpoint({ breakpointId: 'bp-123' })
120
+ * ```
121
+ */
122
+ deleteBreakpoint({ breakpointId }: {
123
+ breakpointId: string;
124
+ }): Promise<void>;
125
+ /**
126
+ * Returns a list of all active breakpoints set by this debugger instance.
127
+ *
128
+ * @returns Array of breakpoint info objects
129
+ *
130
+ * @example
131
+ * ```ts
132
+ * const breakpoints = dbg.listBreakpoints()
133
+ * // [{ id: 'bp-123', file: 'https://example.com/index.js', line: 42 }]
134
+ * ```
135
+ */
136
+ listBreakpoints(): BreakpointInfo[];
137
+ /**
138
+ * Inspects local variables in the current call frame.
139
+ * Must be paused at a breakpoint. String values over 1000 chars are truncated.
140
+ * Use evaluate() for full control over reading specific values.
141
+ *
142
+ * @returns Record of variable names to values
143
+ * @throws Error if not paused or no active call frames
144
+ *
145
+ * @example
146
+ * ```ts
147
+ * const vars = await dbg.inspectLocalVariables()
148
+ * // { myVar: 'hello', count: 42 }
149
+ * ```
150
+ */
151
+ inspectLocalVariables(): Promise<Record<string, unknown>>;
152
+ /**
153
+ * Returns global lexical scope variable names.
154
+ *
155
+ * @returns Array of global variable names
156
+ *
157
+ * @example
158
+ * ```ts
159
+ * const globals = await dbg.inspectGlobalVariables()
160
+ * // ['myGlobal', 'CONFIG']
161
+ * ```
162
+ */
163
+ inspectGlobalVariables(): Promise<string[]>;
164
+ /**
165
+ * Evaluates a JavaScript expression and returns the result.
166
+ * When paused at a breakpoint, evaluates in the current stack frame scope,
167
+ * allowing access to local variables. Otherwise evaluates in global scope.
168
+ * Values are not truncated, use this for full control over reading specific variables.
169
+ *
170
+ * @param options - Options
171
+ * @param options.expression - JavaScript expression to evaluate
172
+ * @returns The result value
173
+ *
174
+ * @example
175
+ * ```ts
176
+ * // When paused, can access local variables:
177
+ * const result = await dbg.evaluate({ expression: 'localVar + 1' })
178
+ *
179
+ * // Read a large string that would be truncated in inspectLocalVariables:
180
+ * const full = await dbg.evaluate({ expression: 'largeStringVar' })
181
+ * ```
182
+ */
183
+ evaluate({ expression }: {
184
+ expression: string;
185
+ }): Promise<EvaluateResult>;
186
+ /**
187
+ * Gets the current execution location when paused at a breakpoint.
188
+ * Includes the call stack and surrounding source code for context.
189
+ *
190
+ * @returns Location info with URL, line number, call stack, and source context
191
+ * @throws Error if debugger is not paused
192
+ *
193
+ * @example
194
+ * ```ts
195
+ * const location = await dbg.getLocation()
196
+ * console.log(location.url) // 'https://example.com/src/index.js'
197
+ * console.log(location.lineNumber) // 42
198
+ * console.log(location.callstack) // [{ functionName: 'handleRequest', ... }]
199
+ * console.log(location.sourceContext)
200
+ * // ' 40: function handleRequest(req) {
201
+ * // 41: const data = req.body
202
+ * // > 42: processData(data)
203
+ * // 43: }'
204
+ * ```
205
+ */
206
+ getLocation(): Promise<LocationInfo>;
207
+ /**
208
+ * Steps over to the next line of code, not entering function calls.
209
+ *
210
+ * @throws Error if debugger is not paused
211
+ *
212
+ * @example
213
+ * ```ts
214
+ * await dbg.stepOver()
215
+ * const newLocation = await dbg.getLocation()
216
+ * ```
217
+ */
218
+ stepOver(): Promise<void>;
219
+ /**
220
+ * Steps into a function call on the current line.
221
+ *
222
+ * @throws Error if debugger is not paused
223
+ *
224
+ * @example
225
+ * ```ts
226
+ * await dbg.stepInto()
227
+ * const location = await dbg.getLocation()
228
+ * // now inside the called function
229
+ * ```
230
+ */
231
+ stepInto(): Promise<void>;
232
+ /**
233
+ * Steps out of the current function, returning to the caller.
234
+ *
235
+ * @throws Error if debugger is not paused
236
+ *
237
+ * @example
238
+ * ```ts
239
+ * await dbg.stepOut()
240
+ * const location = await dbg.getLocation()
241
+ * // back in the calling function
242
+ * ```
243
+ */
244
+ stepOut(): Promise<void>;
245
+ /**
246
+ * Resumes code execution until the next breakpoint or completion.
247
+ *
248
+ * @throws Error if debugger is not paused
249
+ *
250
+ * @example
251
+ * ```ts
252
+ * await dbg.resume()
253
+ * // execution continues
254
+ * ```
255
+ */
256
+ resume(): Promise<void>;
257
+ /**
258
+ * Returns whether the debugger is currently paused at a breakpoint.
259
+ *
260
+ * @returns true if paused, false otherwise
261
+ *
262
+ * @example
263
+ * ```ts
264
+ * if (dbg.isPaused()) {
265
+ * const vars = await dbg.inspectLocalVariables()
266
+ * }
267
+ * ```
268
+ */
269
+ isPaused(): boolean;
270
+ /**
271
+ * Configures the debugger to pause on exceptions.
272
+ *
273
+ * @param options - Options
274
+ * @param options.state - When to pause: 'none' (never), 'uncaught' (only uncaught), or 'all' (all exceptions)
275
+ *
276
+ * @example
277
+ * ```ts
278
+ * // Pause only on uncaught exceptions
279
+ * await dbg.setPauseOnExceptions({ state: 'uncaught' })
280
+ *
281
+ * // Pause on all exceptions (caught and uncaught)
282
+ * await dbg.setPauseOnExceptions({ state: 'all' })
283
+ *
284
+ * // Disable pausing on exceptions
285
+ * await dbg.setPauseOnExceptions({ state: 'none' })
286
+ * ```
287
+ */
288
+ setPauseOnExceptions({ state }: {
289
+ state: 'none' | 'uncaught' | 'all';
290
+ }): Promise<void>;
291
+ /**
292
+ * Lists available scripts where breakpoints can be set.
293
+ * Automatically enables the debugger if not already enabled.
294
+ *
295
+ * @param options - Options
296
+ * @param options.search - Optional string to filter scripts by URL (case-insensitive)
297
+ * @returns Array of up to 20 matching scripts with scriptId and url
298
+ *
299
+ * @example
300
+ * ```ts
301
+ * // List all scripts
302
+ * const scripts = await dbg.listScripts()
303
+ * // [{ scriptId: '1', url: 'https://example.com/app.js' }, ...]
304
+ *
305
+ * // Search for specific files
306
+ * const handlers = await dbg.listScripts({ search: 'handler' })
307
+ * // [{ scriptId: '5', url: 'https://example.com/handlers.js' }]
308
+ * ```
309
+ */
310
+ listScripts({ search }?: {
311
+ search?: string;
312
+ }): Promise<ScriptInfo[]>;
313
+ setXHRBreakpoint({ url }: {
314
+ url: string;
315
+ }): Promise<void>;
316
+ removeXHRBreakpoint({ url }: {
317
+ url: string;
318
+ }): Promise<void>;
319
+ listXHRBreakpoints(): string[];
320
+ /**
321
+ * Sets regex patterns for scripts to blackbox (skip when stepping).
322
+ * Blackboxed scripts are hidden from the call stack and stepped over automatically.
323
+ * Useful for ignoring framework/library code during debugging.
324
+ *
325
+ * @param options - Options
326
+ * @param options.patterns - Array of regex patterns to match script URLs
327
+ *
328
+ * @example
329
+ * ```ts
330
+ * // Skip all node_modules
331
+ * await dbg.setBlackboxPatterns({ patterns: ['node_modules'] })
332
+ *
333
+ * // Skip React and other frameworks
334
+ * await dbg.setBlackboxPatterns({
335
+ * patterns: [
336
+ * 'node_modules/react',
337
+ * 'node_modules/react-dom',
338
+ * 'node_modules/next',
339
+ * 'webpack://',
340
+ * ]
341
+ * })
342
+ *
343
+ * // Skip all third-party scripts
344
+ * await dbg.setBlackboxPatterns({ patterns: ['^https://cdn\\.'] })
345
+ *
346
+ * // Clear all blackbox patterns
347
+ * await dbg.setBlackboxPatterns({ patterns: [] })
348
+ * ```
349
+ */
350
+ setBlackboxPatterns({ patterns }: {
351
+ patterns: string[];
352
+ }): Promise<void>;
353
+ /**
354
+ * Adds a single regex pattern to the blackbox list.
355
+ *
356
+ * @param options - Options
357
+ * @param options.pattern - Regex pattern to match script URLs
358
+ *
359
+ * @example
360
+ * ```ts
361
+ * await dbg.addBlackboxPattern({ pattern: 'node_modules/lodash' })
362
+ * await dbg.addBlackboxPattern({ pattern: 'node_modules/axios' })
363
+ * ```
364
+ */
365
+ addBlackboxPattern({ pattern }: {
366
+ pattern: string;
367
+ }): Promise<void>;
368
+ /**
369
+ * Removes a pattern from the blackbox list.
370
+ *
371
+ * @param options - Options
372
+ * @param options.pattern - The exact pattern string to remove
373
+ */
374
+ removeBlackboxPattern({ pattern }: {
375
+ pattern: string;
376
+ }): Promise<void>;
377
+ /**
378
+ * Returns the current list of blackbox patterns.
379
+ */
380
+ listBlackboxPatterns(): string[];
381
+ private truncateValue;
382
+ private formatPropertyValue;
383
+ private processRemoteObject;
384
+ }
385
+ ```
386
+
387
+ ## Examples
388
+
389
+ ```ts
390
+ import { page, getCDPSession, createDebugger, console } from './debugger-examples-types.js'
391
+
392
+ // Example: List available scripts and set a breakpoint
393
+ async function listScriptsAndSetBreakpoint() {
394
+ const cdp = await getCDPSession({ page })
395
+ const dbg = createDebugger({ cdp })
396
+ await dbg.enable()
397
+
398
+ const scripts = await dbg.listScripts({ search: 'app' })
399
+ console.log(scripts)
400
+
401
+ if (scripts.length > 0) {
402
+ const bpId = await dbg.setBreakpoint({ file: scripts[0].url, line: 100 })
403
+ console.log('Breakpoint set:', bpId)
404
+ }
405
+ }
406
+
407
+ // Example: Inspect state when paused at a breakpoint
408
+ async function inspectWhenPaused() {
409
+ const cdp = await getCDPSession({ page })
410
+ const dbg = createDebugger({ cdp })
411
+ await dbg.enable()
412
+
413
+ if (dbg.isPaused()) {
414
+ const loc = await dbg.getLocation()
415
+ console.log('Paused at:', loc.url, 'line', loc.lineNumber)
416
+ console.log('Source:', loc.sourceContext)
417
+
418
+ const vars = await dbg.inspectLocalVariables()
419
+ console.log('Variables:', vars)
420
+
421
+ const result = await dbg.evaluate({ expression: 'myVar.length' })
422
+ console.log('myVar.length =', result.value)
423
+
424
+ await dbg.stepOver()
425
+ }
426
+ }
427
+
428
+ // Example: Step through code
429
+ async function stepThroughCode() {
430
+ const cdp = await getCDPSession({ page })
431
+ const dbg = createDebugger({ cdp })
432
+ await dbg.enable()
433
+
434
+ await dbg.setBreakpoint({ file: 'https://example.com/app.js', line: 42 })
435
+
436
+ if (dbg.isPaused()) {
437
+ await dbg.stepOver()
438
+ await dbg.stepInto()
439
+ await dbg.stepOut()
440
+ await dbg.resume()
441
+ }
442
+ }
443
+
444
+ // Example: Cleanup all breakpoints
445
+ async function cleanupBreakpoints() {
446
+ const cdp = await getCDPSession({ page })
447
+ const dbg = createDebugger({ cdp })
448
+
449
+ const breakpoints = dbg.listBreakpoints()
450
+ for (const bp of breakpoints) {
451
+ await dbg.deleteBreakpoint({ breakpointId: bp.id })
452
+ }
453
+ }
454
+
455
+ export { listScriptsAndSetBreakpoint, inspectWhenPaused, stepThroughCode, cleanupBreakpoints }
456
+
457
+ ```
@@ -1,7 +1,8 @@
1
- import type { Page } from 'playwright-core';
1
+ import type { Page, Locator } from 'playwright-core';
2
2
  import type { CDPSession } from './cdp-session.js';
3
3
  import type { Debugger } from './debugger.js';
4
4
  import type { Editor } from './editor.js';
5
+ import type { StylesResult } from './styles.js';
5
6
  export declare const page: Page;
6
7
  export declare const getCDPSession: (options: {
7
8
  page: Page;
@@ -12,6 +13,11 @@ export declare const createDebugger: (options: {
12
13
  export declare const createEditor: (options: {
13
14
  cdp: CDPSession;
14
15
  }) => Editor;
16
+ export declare const getStylesForLocator: (options: {
17
+ locator: Locator;
18
+ includeUserAgentStyles?: boolean;
19
+ }) => Promise<StylesResult>;
20
+ export declare const formatStylesAsText: (styles: StylesResult) => string;
15
21
  export declare const console: {
16
22
  log: (...args: unknown[]) => void;
17
23
  };
@@ -1 +1 @@
1
- {"version":3,"file":"debugger-examples-types.d.ts","sourceRoot":"","sources":["../src/debugger-examples-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,MAAM,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,IAAI,CAAA;AAC/B,MAAM,CAAC,OAAO,CAAC,MAAM,aAAa,EAAE,CAAC,OAAO,EAAE;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,KAAK,OAAO,CAAC,UAAU,CAAC,CAAA;AACpF,MAAM,CAAC,OAAO,CAAC,MAAM,cAAc,EAAE,CAAC,OAAO,EAAE;IAAE,GAAG,EAAE,UAAU,CAAA;CAAE,KAAK,QAAQ,CAAA;AAC/E,MAAM,CAAC,OAAO,CAAC,MAAM,YAAY,EAAE,CAAC,OAAO,EAAE;IAAE,GAAG,EAAE,UAAU,CAAA;CAAE,KAAK,MAAM,CAAA;AAC3E,MAAM,CAAC,OAAO,CAAC,MAAM,OAAO,EAAE;IAAE,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;CAAE,CAAA"}
1
+ {"version":3,"file":"debugger-examples-types.d.ts","sourceRoot":"","sources":["../src/debugger-examples-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,MAAM,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,IAAI,CAAA;AAC/B,MAAM,CAAC,OAAO,CAAC,MAAM,aAAa,EAAE,CAAC,OAAO,EAAE;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,KAAK,OAAO,CAAC,UAAU,CAAC,CAAA;AACpF,MAAM,CAAC,OAAO,CAAC,MAAM,cAAc,EAAE,CAAC,OAAO,EAAE;IAAE,GAAG,EAAE,UAAU,CAAA;CAAE,KAAK,QAAQ,CAAA;AAC/E,MAAM,CAAC,OAAO,CAAC,MAAM,YAAY,EAAE,CAAC,OAAO,EAAE;IAAE,GAAG,EAAE,UAAU,CAAA;CAAE,KAAK,MAAM,CAAA;AAC3E,MAAM,CAAC,OAAO,CAAC,MAAM,mBAAmB,EAAE,CAAC,OAAO,EAAE;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,sBAAsB,CAAC,EAAE,OAAO,CAAA;CAAE,KAAK,OAAO,CAAC,YAAY,CAAC,CAAA;AACpI,MAAM,CAAC,OAAO,CAAC,MAAM,kBAAkB,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,MAAM,CAAA;AACzE,MAAM,CAAC,OAAO,CAAC,MAAM,OAAO,EAAE;IAAE,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;CAAE,CAAA"}