forked from Ecwid/control
-
Notifications
You must be signed in to change notification settings - Fork 0
/
page.go
64 lines (57 loc) · 2.17 KB
/
page.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
package control
import (
"github.com/ecwid/control/protocol/browser"
"github.com/ecwid/control/protocol/page"
)
// CaptureScreenshot get screen of current page
func (s Session) CaptureScreenshot(format string, quality int, clip *page.Viewport, fromSurface, captureBeyondViewport bool) ([]byte, error) {
val, err := page.CaptureScreenshot(s, page.CaptureScreenshotArgs{
Format: format,
Quality: quality,
Clip: clip,
FromSurface: fromSurface,
CaptureBeyondViewport: captureBeyondViewport,
})
if err != nil {
return nil, err
}
return val.Data, nil
}
// AddScriptToEvaluateOnNewDocument https://chromedevtools.github.io/devtools-protocol/tot/Page#method-addScriptToEvaluateOnNewDocument
func (s Session) AddScriptToEvaluateOnNewDocument(source string) (page.ScriptIdentifier, error) {
val, err := page.AddScriptToEvaluateOnNewDocument(s, page.AddScriptToEvaluateOnNewDocumentArgs{
Source: source,
})
if err != nil {
return "", err
}
return val.Identifier, nil
}
// RemoveScriptToEvaluateOnNewDocument https://chromedevtools.github.io/devtools-protocol/tot/Page#method-removeScriptToEvaluateOnNewDocument
func (s Session) RemoveScriptToEvaluateOnNewDocument(identifier page.ScriptIdentifier) error {
return page.RemoveScriptToEvaluateOnNewDocument(s, page.RemoveScriptToEvaluateOnNewDocumentArgs{
Identifier: identifier,
})
}
// SetDownloadBehavior https://chromedevtools.github.io/devtools-protocol/tot/Page#method-setDownloadBehavior
func (s Session) SetDownloadBehavior(behavior string, downloadPath string, eventsEnabled bool) error {
return browser.SetDownloadBehavior(s, browser.SetDownloadBehaviorArgs{
Behavior: behavior,
DownloadPath: downloadPath,
EventsEnabled: eventsEnabled, // default false
})
}
// HandleJavaScriptDialog ...
func (s Session) HandleJavaScriptDialog(accept bool, promptText string) error {
return page.HandleJavaScriptDialog(s, page.HandleJavaScriptDialogArgs{
Accept: accept,
PromptText: promptText,
})
}
func (s Session) GetLayoutMetrics() (*page.GetLayoutMetricsVal, error) {
view, err := page.GetLayoutMetrics(s)
if err != nil {
return nil, err
}
return view, nil
}