-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpage_action.go
57 lines (48 loc) · 1.22 KB
/
page_action.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
package chromy
import (
"bytes"
"context"
"io"
"github.com/mafredri/cdp/protocol/page"
)
func Navigate(URL string) Action {
return actionWrapper("navigate", ActionFunc(func(ctx context.Context, t *Target) error {
_, err := t.Client().Page.Navigate(ctx, page.NewNavigateArgs(URL))
return err
}))
}
func DocumentReady() Action {
return actionWrapper("documentReady", ActionFunc(func(ctx context.Context, t *Target) error {
c := t.domain.Page.events.DOMContentEventFiredClient
select {
case <-c.Ready():
_, err := c.Recv()
return err
case <-ctx.Done():
return ctx.Err()
}
}))
}
func PageLoaded() Action {
return actionWrapper("pageLoaded", ActionFunc(func(ctx context.Context, t *Target) error {
c := t.domain.Page.events.LoadEventFiredClient
select {
case <-c.Ready():
_, err := c.Recv()
return err
case <-ctx.Done():
return ctx.Err()
}
}))
}
func CaptureScreenshot(w io.Writer) Action {
return actionWrapper("captureScreenshot", ActionFunc(func(ctx context.Context, t *Target) error {
reply, err := t.Client().Page.CaptureScreenshot(ctx, page.NewCaptureScreenshotArgs())
if err != nil {
return err
}
buf := bytes.NewBuffer(reply.Data)
_, err = io.Copy(w, buf)
return err
}))
}