-
Notifications
You must be signed in to change notification settings - Fork 48
/
domain.go
534 lines (480 loc) · 19.2 KB
/
domain.go
1
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
27
28
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
// Code generated by cdpgen. DO NOT EDIT.
// Package debugger implements the Debugger domain. Debugger domain exposes
// JavaScript debugging capabilities. It allows setting and removing
// breakpoints, stepping through execution, exploring stack traces, etc.
package debugger
import (
"context"
"github.com/mafredri/cdp/protocol/internal"
"github.com/mafredri/cdp/rpcc"
)
// domainClient is a client for the Debugger domain. Debugger domain exposes
// JavaScript debugging capabilities. It allows setting and removing
// breakpoints, stepping through execution, exploring stack traces, etc.
type domainClient struct{ conn *rpcc.Conn }
// NewClient returns a client for the Debugger domain with the connection set to conn.
func NewClient(conn *rpcc.Conn) *domainClient {
return &domainClient{conn: conn}
}
// ContinueToLocation invokes the Debugger method. Continues execution until
// specific location is reached.
func (d *domainClient) ContinueToLocation(ctx context.Context, args *ContinueToLocationArgs) (err error) {
if args != nil {
err = rpcc.Invoke(ctx, "Debugger.continueToLocation", args, nil, d.conn)
} else {
err = rpcc.Invoke(ctx, "Debugger.continueToLocation", nil, nil, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "ContinueToLocation", Err: err}
}
return
}
// Disable invokes the Debugger method. Disables debugger for given page.
func (d *domainClient) Disable(ctx context.Context) (err error) {
err = rpcc.Invoke(ctx, "Debugger.disable", nil, nil, d.conn)
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "Disable", Err: err}
}
return
}
// Enable invokes the Debugger method. Enables debugger for the given page.
// Clients should not assume that the debugging has been enabled until the
// result for this command is received.
func (d *domainClient) Enable(ctx context.Context, args *EnableArgs) (reply *EnableReply, err error) {
reply = new(EnableReply)
if args != nil {
err = rpcc.Invoke(ctx, "Debugger.enable", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "Debugger.enable", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "Enable", Err: err}
}
return
}
// EvaluateOnCallFrame invokes the Debugger method. Evaluates expression on a
// given call frame.
func (d *domainClient) EvaluateOnCallFrame(ctx context.Context, args *EvaluateOnCallFrameArgs) (reply *EvaluateOnCallFrameReply, err error) {
reply = new(EvaluateOnCallFrameReply)
if args != nil {
err = rpcc.Invoke(ctx, "Debugger.evaluateOnCallFrame", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "Debugger.evaluateOnCallFrame", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "EvaluateOnCallFrame", Err: err}
}
return
}
// GetPossibleBreakpoints invokes the Debugger method. Returns possible
// locations for breakpoint. scriptId in start and end range locations should
// be the same.
func (d *domainClient) GetPossibleBreakpoints(ctx context.Context, args *GetPossibleBreakpointsArgs) (reply *GetPossibleBreakpointsReply, err error) {
reply = new(GetPossibleBreakpointsReply)
if args != nil {
err = rpcc.Invoke(ctx, "Debugger.getPossibleBreakpoints", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "Debugger.getPossibleBreakpoints", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "GetPossibleBreakpoints", Err: err}
}
return
}
// GetScriptSource invokes the Debugger method. Returns source for the script
// with given id.
func (d *domainClient) GetScriptSource(ctx context.Context, args *GetScriptSourceArgs) (reply *GetScriptSourceReply, err error) {
reply = new(GetScriptSourceReply)
if args != nil {
err = rpcc.Invoke(ctx, "Debugger.getScriptSource", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "Debugger.getScriptSource", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "GetScriptSource", Err: err}
}
return
}
// GetStackTrace invokes the Debugger method. Returns stack trace with given
// `stackTraceId`.
func (d *domainClient) GetStackTrace(ctx context.Context, args *GetStackTraceArgs) (reply *GetStackTraceReply, err error) {
reply = new(GetStackTraceReply)
if args != nil {
err = rpcc.Invoke(ctx, "Debugger.getStackTrace", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "Debugger.getStackTrace", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "GetStackTrace", Err: err}
}
return
}
// Pause invokes the Debugger method. Stops on the next JavaScript statement.
func (d *domainClient) Pause(ctx context.Context) (err error) {
err = rpcc.Invoke(ctx, "Debugger.pause", nil, nil, d.conn)
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "Pause", Err: err}
}
return
}
// PauseOnAsyncCall invokes the Debugger method.
func (d *domainClient) PauseOnAsyncCall(ctx context.Context, args *PauseOnAsyncCallArgs) (err error) {
if args != nil {
err = rpcc.Invoke(ctx, "Debugger.pauseOnAsyncCall", args, nil, d.conn)
} else {
err = rpcc.Invoke(ctx, "Debugger.pauseOnAsyncCall", nil, nil, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "PauseOnAsyncCall", Err: err}
}
return
}
// RemoveBreakpoint invokes the Debugger method. Removes JavaScript
// breakpoint.
func (d *domainClient) RemoveBreakpoint(ctx context.Context, args *RemoveBreakpointArgs) (err error) {
if args != nil {
err = rpcc.Invoke(ctx, "Debugger.removeBreakpoint", args, nil, d.conn)
} else {
err = rpcc.Invoke(ctx, "Debugger.removeBreakpoint", nil, nil, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "RemoveBreakpoint", Err: err}
}
return
}
// RestartFrame invokes the Debugger method. Restarts particular call frame
// from the beginning.
func (d *domainClient) RestartFrame(ctx context.Context, args *RestartFrameArgs) (reply *RestartFrameReply, err error) {
reply = new(RestartFrameReply)
if args != nil {
err = rpcc.Invoke(ctx, "Debugger.restartFrame", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "Debugger.restartFrame", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "RestartFrame", Err: err}
}
return
}
// Resume invokes the Debugger method. Resumes JavaScript execution.
func (d *domainClient) Resume(ctx context.Context) (err error) {
err = rpcc.Invoke(ctx, "Debugger.resume", nil, nil, d.conn)
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "Resume", Err: err}
}
return
}
// SearchInContent invokes the Debugger method. Searches for given string in
// script content.
func (d *domainClient) SearchInContent(ctx context.Context, args *SearchInContentArgs) (reply *SearchInContentReply, err error) {
reply = new(SearchInContentReply)
if args != nil {
err = rpcc.Invoke(ctx, "Debugger.searchInContent", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "Debugger.searchInContent", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "SearchInContent", Err: err}
}
return
}
// SetAsyncCallStackDepth invokes the Debugger method. Enables or disables
// async call stacks tracking.
func (d *domainClient) SetAsyncCallStackDepth(ctx context.Context, args *SetAsyncCallStackDepthArgs) (err error) {
if args != nil {
err = rpcc.Invoke(ctx, "Debugger.setAsyncCallStackDepth", args, nil, d.conn)
} else {
err = rpcc.Invoke(ctx, "Debugger.setAsyncCallStackDepth", nil, nil, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "SetAsyncCallStackDepth", Err: err}
}
return
}
// SetBlackboxPatterns invokes the Debugger method. Replace previous blackbox
// patterns with passed ones. Forces backend to skip stepping/pausing in
// scripts with url matching one of the patterns. VM will try to leave
// blackboxed script by performing 'step in' several times, finally resorting
// to 'step out' if unsuccessful.
func (d *domainClient) SetBlackboxPatterns(ctx context.Context, args *SetBlackboxPatternsArgs) (err error) {
if args != nil {
err = rpcc.Invoke(ctx, "Debugger.setBlackboxPatterns", args, nil, d.conn)
} else {
err = rpcc.Invoke(ctx, "Debugger.setBlackboxPatterns", nil, nil, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "SetBlackboxPatterns", Err: err}
}
return
}
// SetBlackboxedRanges invokes the Debugger method. Makes backend skip steps
// in the script in blackboxed ranges. VM will try leave blacklisted scripts by
// performing 'step in' several times, finally resorting to 'step out' if
// unsuccessful. Positions array contains positions where blackbox state is
// changed. First interval isn't blackboxed. Array should be sorted.
func (d *domainClient) SetBlackboxedRanges(ctx context.Context, args *SetBlackboxedRangesArgs) (err error) {
if args != nil {
err = rpcc.Invoke(ctx, "Debugger.setBlackboxedRanges", args, nil, d.conn)
} else {
err = rpcc.Invoke(ctx, "Debugger.setBlackboxedRanges", nil, nil, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "SetBlackboxedRanges", Err: err}
}
return
}
// SetBreakpoint invokes the Debugger method. Sets JavaScript breakpoint at a
// given location.
func (d *domainClient) SetBreakpoint(ctx context.Context, args *SetBreakpointArgs) (reply *SetBreakpointReply, err error) {
reply = new(SetBreakpointReply)
if args != nil {
err = rpcc.Invoke(ctx, "Debugger.setBreakpoint", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "Debugger.setBreakpoint", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "SetBreakpoint", Err: err}
}
return
}
// SetInstrumentationBreakpoint invokes the Debugger method. Sets
// instrumentation breakpoint.
func (d *domainClient) SetInstrumentationBreakpoint(ctx context.Context, args *SetInstrumentationBreakpointArgs) (reply *SetInstrumentationBreakpointReply, err error) {
reply = new(SetInstrumentationBreakpointReply)
if args != nil {
err = rpcc.Invoke(ctx, "Debugger.setInstrumentationBreakpoint", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "Debugger.setInstrumentationBreakpoint", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "SetInstrumentationBreakpoint", Err: err}
}
return
}
// SetBreakpointByURL invokes the Debugger method. Sets JavaScript breakpoint
// at given location specified either by URL or URL regex. Once this command is
// issued, all existing parsed scripts will have breakpoints resolved and
// returned in `locations` property. Further matching script parsing will
// result in subsequent `breakpointResolved` events issued. This logical
// breakpoint will survive page reloads.
func (d *domainClient) SetBreakpointByURL(ctx context.Context, args *SetBreakpointByURLArgs) (reply *SetBreakpointByURLReply, err error) {
reply = new(SetBreakpointByURLReply)
if args != nil {
err = rpcc.Invoke(ctx, "Debugger.setBreakpointByUrl", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "Debugger.setBreakpointByUrl", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "SetBreakpointByURL", Err: err}
}
return
}
// SetBreakpointOnFunctionCall invokes the Debugger method. Sets JavaScript
// breakpoint before each call to the given function. If another function was
// created from the same source as a given one, calling it will also trigger
// the breakpoint.
func (d *domainClient) SetBreakpointOnFunctionCall(ctx context.Context, args *SetBreakpointOnFunctionCallArgs) (reply *SetBreakpointOnFunctionCallReply, err error) {
reply = new(SetBreakpointOnFunctionCallReply)
if args != nil {
err = rpcc.Invoke(ctx, "Debugger.setBreakpointOnFunctionCall", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "Debugger.setBreakpointOnFunctionCall", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "SetBreakpointOnFunctionCall", Err: err}
}
return
}
// SetBreakpointsActive invokes the Debugger method. Activates / deactivates
// all breakpoints on the page.
func (d *domainClient) SetBreakpointsActive(ctx context.Context, args *SetBreakpointsActiveArgs) (err error) {
if args != nil {
err = rpcc.Invoke(ctx, "Debugger.setBreakpointsActive", args, nil, d.conn)
} else {
err = rpcc.Invoke(ctx, "Debugger.setBreakpointsActive", nil, nil, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "SetBreakpointsActive", Err: err}
}
return
}
// SetPauseOnExceptions invokes the Debugger method. Defines pause on
// exceptions state. Can be set to stop on all exceptions, uncaught exceptions
// or no exceptions. Initial pause on exceptions state is `none`.
func (d *domainClient) SetPauseOnExceptions(ctx context.Context, args *SetPauseOnExceptionsArgs) (err error) {
if args != nil {
err = rpcc.Invoke(ctx, "Debugger.setPauseOnExceptions", args, nil, d.conn)
} else {
err = rpcc.Invoke(ctx, "Debugger.setPauseOnExceptions", nil, nil, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "SetPauseOnExceptions", Err: err}
}
return
}
// SetReturnValue invokes the Debugger method. Changes return value in top
// frame. Available only at return break position.
func (d *domainClient) SetReturnValue(ctx context.Context, args *SetReturnValueArgs) (err error) {
if args != nil {
err = rpcc.Invoke(ctx, "Debugger.setReturnValue", args, nil, d.conn)
} else {
err = rpcc.Invoke(ctx, "Debugger.setReturnValue", nil, nil, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "SetReturnValue", Err: err}
}
return
}
// SetScriptSource invokes the Debugger method. Edits JavaScript source live.
func (d *domainClient) SetScriptSource(ctx context.Context, args *SetScriptSourceArgs) (reply *SetScriptSourceReply, err error) {
reply = new(SetScriptSourceReply)
if args != nil {
err = rpcc.Invoke(ctx, "Debugger.setScriptSource", args, reply, d.conn)
} else {
err = rpcc.Invoke(ctx, "Debugger.setScriptSource", nil, reply, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "SetScriptSource", Err: err}
}
return
}
// SetSkipAllPauses invokes the Debugger method. Makes page not interrupt on
// any pauses (breakpoint, exception, dom exception etc).
func (d *domainClient) SetSkipAllPauses(ctx context.Context, args *SetSkipAllPausesArgs) (err error) {
if args != nil {
err = rpcc.Invoke(ctx, "Debugger.setSkipAllPauses", args, nil, d.conn)
} else {
err = rpcc.Invoke(ctx, "Debugger.setSkipAllPauses", nil, nil, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "SetSkipAllPauses", Err: err}
}
return
}
// SetVariableValue invokes the Debugger method. Changes value of variable in
// a callframe. Object-based scopes are not supported and must be mutated
// manually.
func (d *domainClient) SetVariableValue(ctx context.Context, args *SetVariableValueArgs) (err error) {
if args != nil {
err = rpcc.Invoke(ctx, "Debugger.setVariableValue", args, nil, d.conn)
} else {
err = rpcc.Invoke(ctx, "Debugger.setVariableValue", nil, nil, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "SetVariableValue", Err: err}
}
return
}
// StepInto invokes the Debugger method. Steps into the function call.
func (d *domainClient) StepInto(ctx context.Context, args *StepIntoArgs) (err error) {
if args != nil {
err = rpcc.Invoke(ctx, "Debugger.stepInto", args, nil, d.conn)
} else {
err = rpcc.Invoke(ctx, "Debugger.stepInto", nil, nil, d.conn)
}
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "StepInto", Err: err}
}
return
}
// StepOut invokes the Debugger method. Steps out of the function call.
func (d *domainClient) StepOut(ctx context.Context) (err error) {
err = rpcc.Invoke(ctx, "Debugger.stepOut", nil, nil, d.conn)
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "StepOut", Err: err}
}
return
}
// StepOver invokes the Debugger method. Steps over the statement.
func (d *domainClient) StepOver(ctx context.Context) (err error) {
err = rpcc.Invoke(ctx, "Debugger.stepOver", nil, nil, d.conn)
if err != nil {
err = &internal.OpError{Domain: "Debugger", Op: "StepOver", Err: err}
}
return
}
func (d *domainClient) BreakpointResolved(ctx context.Context) (BreakpointResolvedClient, error) {
s, err := rpcc.NewStream(ctx, "Debugger.breakpointResolved", d.conn)
if err != nil {
return nil, err
}
return &breakpointResolvedClient{Stream: s}, nil
}
type breakpointResolvedClient struct{ rpcc.Stream }
// GetStream returns the original Stream for use with cdp.Sync.
func (c *breakpointResolvedClient) GetStream() rpcc.Stream { return c.Stream }
func (c *breakpointResolvedClient) Recv() (*BreakpointResolvedReply, error) {
event := new(BreakpointResolvedReply)
if err := c.RecvMsg(event); err != nil {
return nil, &internal.OpError{Domain: "Debugger", Op: "BreakpointResolved Recv", Err: err}
}
return event, nil
}
func (d *domainClient) Paused(ctx context.Context) (PausedClient, error) {
s, err := rpcc.NewStream(ctx, "Debugger.paused", d.conn)
if err != nil {
return nil, err
}
return &pausedClient{Stream: s}, nil
}
type pausedClient struct{ rpcc.Stream }
// GetStream returns the original Stream for use with cdp.Sync.
func (c *pausedClient) GetStream() rpcc.Stream { return c.Stream }
func (c *pausedClient) Recv() (*PausedReply, error) {
event := new(PausedReply)
if err := c.RecvMsg(event); err != nil {
return nil, &internal.OpError{Domain: "Debugger", Op: "Paused Recv", Err: err}
}
return event, nil
}
func (d *domainClient) Resumed(ctx context.Context) (ResumedClient, error) {
s, err := rpcc.NewStream(ctx, "Debugger.resumed", d.conn)
if err != nil {
return nil, err
}
return &resumedClient{Stream: s}, nil
}
type resumedClient struct{ rpcc.Stream }
// GetStream returns the original Stream for use with cdp.Sync.
func (c *resumedClient) GetStream() rpcc.Stream { return c.Stream }
func (c *resumedClient) Recv() (*ResumedReply, error) {
event := new(ResumedReply)
if err := c.RecvMsg(event); err != nil {
return nil, &internal.OpError{Domain: "Debugger", Op: "Resumed Recv", Err: err}
}
return event, nil
}
func (d *domainClient) ScriptFailedToParse(ctx context.Context) (ScriptFailedToParseClient, error) {
s, err := rpcc.NewStream(ctx, "Debugger.scriptFailedToParse", d.conn)
if err != nil {
return nil, err
}
return &scriptFailedToParseClient{Stream: s}, nil
}
type scriptFailedToParseClient struct{ rpcc.Stream }
// GetStream returns the original Stream for use with cdp.Sync.
func (c *scriptFailedToParseClient) GetStream() rpcc.Stream { return c.Stream }
func (c *scriptFailedToParseClient) Recv() (*ScriptFailedToParseReply, error) {
event := new(ScriptFailedToParseReply)
if err := c.RecvMsg(event); err != nil {
return nil, &internal.OpError{Domain: "Debugger", Op: "ScriptFailedToParse Recv", Err: err}
}
return event, nil
}
func (d *domainClient) ScriptParsed(ctx context.Context) (ScriptParsedClient, error) {
s, err := rpcc.NewStream(ctx, "Debugger.scriptParsed", d.conn)
if err != nil {
return nil, err
}
return &scriptParsedClient{Stream: s}, nil
}
type scriptParsedClient struct{ rpcc.Stream }
// GetStream returns the original Stream for use with cdp.Sync.
func (c *scriptParsedClient) GetStream() rpcc.Stream { return c.Stream }
func (c *scriptParsedClient) Recv() (*ScriptParsedReply, error) {
event := new(ScriptParsedReply)
if err := c.RecvMsg(event); err != nil {
return nil, &internal.OpError{Domain: "Debugger", Op: "ScriptParsed Recv", Err: err}
}
return event, nil
}