forked from mkenney/go-chrome
/
cdtp.overlay.go
476 lines (402 loc) · 13.8 KB
/
cdtp.overlay.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
package socket
import (
"encoding/json"
"github.com/mkenney/go-chrome/tot/overlay"
)
/*
OverlayProtocol provides a namespace for the Chrome Overlay protocol methods.
The Overlay protocol provides various functionality related to drawing atop the
inspected page.
https://chromedevtools.github.io/devtools-protocol/tot/Overlay/ EXPERIMENTAL.
*/
type OverlayProtocol struct {
Socket Socketer
}
/*
Disable disables domain notifications.
https://chromedevtools.github.io/devtools-protocol/tot/Overlay/#method-disable
*/
func (protocol *OverlayProtocol) Disable() <-chan *overlay.DisableResult {
resultChan := make(chan *overlay.DisableResult)
command := NewCommand(protocol.Socket, "Overlay.disable", nil)
result := &overlay.DisableResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
Enable enables domain notifications.
https://chromedevtools.github.io/devtools-protocol/tot/Overlay/#method-enable
*/
func (protocol *OverlayProtocol) Enable() <-chan *overlay.EnableResult {
resultChan := make(chan *overlay.EnableResult)
command := NewCommand(protocol.Socket, "Overlay.enable", nil)
result := &overlay.EnableResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
GetHighlightObjectForTest is for testing.
https://chromedevtools.github.io/devtools-protocol/tot/Overlay/#method-getHighlightObjectForTest
*/
func (protocol *OverlayProtocol) GetHighlightObjectForTest(
params *overlay.GetHighlightObjectForTestParams,
) <-chan *overlay.GetHighlightObjectForTestResult {
resultChan := make(chan *overlay.GetHighlightObjectForTestResult)
command := NewCommand(protocol.Socket, "Overlay.getHighlightObjectForTest", params)
result := &overlay.GetHighlightObjectForTestResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
} else {
result.Err = json.Unmarshal(response.Result, &result)
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
HideHighlight hides any highlight.
https://chromedevtools.github.io/devtools-protocol/tot/Overlay/#method-hideHighlight
*/
func (protocol *OverlayProtocol) HideHighlight() <-chan *overlay.HideHighlightResult {
resultChan := make(chan *overlay.HideHighlightResult)
command := NewCommand(protocol.Socket, "Overlay.hideHighlight", nil)
result := &overlay.HideHighlightResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
HighlightFrame highlights owner element of the frame with given ID.
https://chromedevtools.github.io/devtools-protocol/tot/Overlay/#method-highlightFrame
*/
func (protocol *OverlayProtocol) HighlightFrame(
params *overlay.HighlightFrameParams,
) <-chan *overlay.HighlightFrameResult {
resultChan := make(chan *overlay.HighlightFrameResult)
command := NewCommand(protocol.Socket, "Overlay.highlightFrame", params)
result := &overlay.HighlightFrameResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
HighlightNode highlights DOM node with given ID or with the given JavaScript
object wrapper. Either nodeID or objectID must be specified.
https://chromedevtools.github.io/devtools-protocol/tot/Overlay/#method-highlightNode
*/
func (protocol *OverlayProtocol) HighlightNode(
params *overlay.HighlightNodeParams,
) <-chan *overlay.HighlightNodeResult {
resultChan := make(chan *overlay.HighlightNodeResult)
command := NewCommand(protocol.Socket, "Overlay.highlightNode", params)
result := &overlay.HighlightNodeResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
HighlightQuad highlights given quad. Coordinates are absolute with respect to
the main frame viewport.
https://chromedevtools.github.io/devtools-protocol/tot/Overlay/#method-highlightQuad
*/
func (protocol *OverlayProtocol) HighlightQuad(
params *overlay.HighlightQuadParams,
) <-chan *overlay.HighlightQuadResult {
resultChan := make(chan *overlay.HighlightQuadResult)
command := NewCommand(protocol.Socket, "Overlay.highlightQuad", params)
result := &overlay.HighlightQuadResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
HighlightRect highlights given rectangle. Coordinates are absolute with respect
to the main frame viewport.
https://chromedevtools.github.io/devtools-protocol/tot/Overlay/#method-highlightRect
*/
func (protocol *OverlayProtocol) HighlightRect(
params *overlay.HighlightRectParams,
) <-chan *overlay.HighlightRectResult {
resultChan := make(chan *overlay.HighlightRectResult)
command := NewCommand(protocol.Socket, "Overlay.highlightRect", params)
result := &overlay.HighlightRectResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
SetInspectMode enters the 'inspect' mode. In this mode, elements that user is
hovering over are highlighted. Backend then generates 'inspectNodeRequested'
event upon element selection.
https://chromedevtools.github.io/devtools-protocol/tot/Overlay/#method-setInspectMode
*/
func (protocol *OverlayProtocol) SetInspectMode(
params *overlay.SetInspectModeParams,
) <-chan *overlay.SetInspectModeResult {
resultChan := make(chan *overlay.SetInspectModeResult)
command := NewCommand(protocol.Socket, "Overlay.setInspectMode", params)
result := &overlay.SetInspectModeResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
SetPausedInDebuggerMessage sets the paused message
https://chromedevtools.github.io/devtools-protocol/tot/Overlay/#method-setPausedInDebuggerMessage
*/
func (protocol *OverlayProtocol) SetPausedInDebuggerMessage(
params *overlay.SetPausedInDebuggerMessageParams,
) <-chan *overlay.SetPausedInDebuggerMessageResult {
resultChan := make(chan *overlay.SetPausedInDebuggerMessageResult)
command := NewCommand(protocol.Socket, "Overlay.setPausedInDebuggerMessage", params)
result := &overlay.SetPausedInDebuggerMessageResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
SetShowDebugBorders requests that backend shows debug borders on layers.
https://chromedevtools.github.io/devtools-protocol/tot/Overlay/#method-setShowDebugBorders
*/
func (protocol *OverlayProtocol) SetShowDebugBorders(
params *overlay.SetShowDebugBordersParams,
) <-chan *overlay.SetShowDebugBordersResult {
resultChan := make(chan *overlay.SetShowDebugBordersResult)
command := NewCommand(protocol.Socket, "Overlay.setShowDebugBorders", params)
result := &overlay.SetShowDebugBordersResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
SetShowFPSCounter requests that backend shows the FPS counter.
https://chromedevtools.github.io/devtools-protocol/tot/Overlay/#method-setShowFPSCounter
*/
func (protocol *OverlayProtocol) SetShowFPSCounter(
params *overlay.SetShowFPSCounterParams,
) <-chan *overlay.SetShowFPSCounterResult {
resultChan := make(chan *overlay.SetShowFPSCounterResult)
command := NewCommand(protocol.Socket, "Overlay.setShowFPSCounter", params)
result := &overlay.SetShowFPSCounterResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
SetShowPaintRects that backend shows paint rectangles.
https://chromedevtools.github.io/devtools-protocol/tot/Overlay/#method-setShowPaintRects
*/
func (protocol *OverlayProtocol) SetShowPaintRects(
params *overlay.SetShowPaintRectsParams,
) <-chan *overlay.SetShowPaintRectsResult {
resultChan := make(chan *overlay.SetShowPaintRectsResult)
command := NewCommand(protocol.Socket, "Overlay.setShowPaintRects", params)
result := &overlay.SetShowPaintRectsResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
SetShowScrollBottleneckRects requests that backend shows scroll bottleneck rects.
https://chromedevtools.github.io/devtools-protocol/tot/Overlay/#method-setShowScrollBottleneckRects
*/
func (protocol *OverlayProtocol) SetShowScrollBottleneckRects(
params *overlay.SetShowScrollBottleneckRectsParams,
) <-chan *overlay.SetShowScrollBottleneckRectsResult {
resultChan := make(chan *overlay.SetShowScrollBottleneckRectsResult)
command := NewCommand(protocol.Socket, "Overlay.setShowScrollBottleneckRects", params)
result := &overlay.SetShowScrollBottleneckRectsResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
SetShowViewportSizeOnResize paints viewport size upon main frame resize.
https://chromedevtools.github.io/devtools-protocol/tot/Overlay/#method-setShowViewportSizeOnResize
*/
func (protocol *OverlayProtocol) SetShowViewportSizeOnResize(
params *overlay.SetShowViewportSizeOnResizeParams,
) <-chan *overlay.SetShowViewportSizeOnResizeResult {
resultChan := make(chan *overlay.SetShowViewportSizeOnResizeResult)
command := NewCommand(protocol.Socket, "Overlay.setShowViewportSizeOnResize", params)
result := &overlay.SetShowViewportSizeOnResizeResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
SetSuspended sets the suspended state
https://chromedevtools.github.io/devtools-protocol/tot/Overlay/#method-setSuspended
*/
func (protocol *OverlayProtocol) SetSuspended(
params *overlay.SetSuspendedParams,
) <-chan *overlay.SetSuspendedResult {
resultChan := make(chan *overlay.SetSuspendedResult)
command := NewCommand(protocol.Socket, "Overlay.setSuspended", params)
result := &overlay.SetSuspendedResult{}
go func() {
response := <-protocol.Socket.SendCommand(command)
if nil != response.Error && 0 != response.Error.Code {
result.Err = response.Error
}
resultChan <- result
close(resultChan)
}()
return resultChan
}
/*
OnInspectNodeRequested adds a handler to the Overlay.inspectNodeRequested event.
Overlay.inspectNodeRequested fires when the node should be inspected. This
happens after call to `setInspectMode` or when user manually inspects an
element.
https://chromedevtools.github.io/devtools-protocol/tot/Overlay/#event-inspectNodeRequested
*/
func (protocol *OverlayProtocol) OnInspectNodeRequested(
callback func(event *overlay.InspectNodeRequestedEvent),
) {
handler := NewEventHandler(
"Overlay.inspectNodeRequested",
func(response *Response) {
event := &overlay.InspectNodeRequestedEvent{}
json.Unmarshal([]byte(response.Params), event)
if nil != response.Error && 0 != response.Error.Code {
event.Err = response.Error
}
callback(event)
},
)
protocol.Socket.AddEventHandler(handler)
}
/*
OnNodeHighlightRequested adds a handler to the Overlay.nodeHighlightRequested
event. Overlay.nodeHighlightRequested fires when the node should be highlighted.
This happens after call to `setInspectMode`.
https://chromedevtools.github.io/devtools-protocol/tot/Overlay/#event-nodeHighlightRequested
*/
func (protocol *OverlayProtocol) OnNodeHighlightRequested(
callback func(event *overlay.NodeHighlightRequestedEvent),
) {
handler := NewEventHandler(
"Overlay.nodeHighlightRequested",
func(response *Response) {
event := &overlay.NodeHighlightRequestedEvent{}
json.Unmarshal([]byte(response.Params), event)
if nil != response.Error && 0 != response.Error.Code {
event.Err = response.Error
}
callback(event)
},
)
protocol.Socket.AddEventHandler(handler)
}
/*
OnScreenshotRequested adds a handler to the Overlay.screenshotRequested event.
Overlay.screenshotRequested fires when user asks to capture screenshot of some
area on the page.
https://chromedevtools.github.io/devtools-protocol/tot/Overlay/#event-screenshotRequested
*/
func (protocol *OverlayProtocol) OnScreenshotRequested(
callback func(event *overlay.ScreenshotRequestedEvent),
) {
handler := NewEventHandler(
"Overlay.screenshotRequested",
func(response *Response) {
event := &overlay.ScreenshotRequestedEvent{}
json.Unmarshal([]byte(response.Params), event)
if nil != response.Error && 0 != response.Error.Code {
event.Err = response.Error
}
callback(event)
},
)
protocol.Socket.AddEventHandler(handler)
}