forked from playwright-community/playwright-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (50 loc) · 1.27 KB
/
main.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
//go:build ignore
// +build ignore
package main
import (
"fmt"
"log"
"github.com/playwright-community/playwright-go"
)
func main() {
pw, err := playwright.Run()
if err != nil {
log.Fatalf("could not launch playwright: %v", err)
}
browser, err := pw.Chromium.Launch()
if err != nil {
log.Fatalf("could not launch Chromium: %v", err)
}
page, err := browser.NewPage(playwright.BrowserNewContextOptions{
RecordVideo: &playwright.BrowserNewContextOptionsRecordVideo{
Dir: playwright.String("videos/"),
},
})
if err != nil {
log.Fatalf("could not create page: %v", err)
}
gotoPage := func(url string) {
fmt.Printf("Visiting %s\n", url)
if _, err = page.Goto(url); err != nil {
log.Fatalf("could not goto: %v", err)
}
fmt.Printf("Visited %s\n", url)
}
gotoPage("http://whatsmyuseragent.org")
gotoPage("https://github.com")
gotoPage("https://microsoft.com")
if err := page.Close(); err != nil {
log.Fatalf("failed to close page: %v", err)
}
path, err := page.Video().Path()
if err != nil {
log.Fatalf("failed to get video path: %v", err)
}
fmt.Printf("Saved to %s\n", path)
if err = browser.Close(); err != nil {
log.Fatalf("could not close browser: %v", err)
}
if err = pw.Stop(); err != nil {
log.Fatalf("could not stop Playwright: %v", err)
}
}