-
-
Notifications
You must be signed in to change notification settings - Fork 321
/
main.go
52 lines (39 loc) · 1.59 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
// Package main ...
package main
import (
"fmt"
"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/launcher"
"github.com/go-rod/rod/lib/utils"
)
func main() {
// This example is to launch a browser remotely, not connect to a running browser remotely,
// to connect to a running browser check the "../connect-browser" example.
// Rod provides a docker image for beginners, run the below to start a launcher.Manager:
//
// docker run -p 7317:7317 ghcr.io/go-rod/rod
//
// For available CLI flags run: docker run ghcr.io/go-rod/rod rod-manager -h
// For more information, check the doc of launcher.Manager
l := launcher.MustNewManaged("")
// You can also set any flag remotely before you launch the remote browser.
// Available flags: https://peter.sh/experiments/chromium-command-line-switches
l.Set("disable-gpu").Delete("disable-gpu")
// Launch with headful mode
l.Headless(false).XVFB("--server-num=5", "--server-args=-screen 0 1600x900x16")
browser := rod.New().Client(l.MustClient()).MustConnect()
// You may want to start a server to watch the screenshots of the remote browser.
launcher.Open(browser.ServeMonitor(""))
fmt.Println(
browser.MustPage("https://mdn.dev/").MustEval("() => document.title"),
)
// Launch another browser with the same docker container.
ll := launcher.MustNewManaged("")
// You can set different flags for each browser.
ll.Set("disable-sync").Delete("disable-sync")
anotherBrowser := rod.New().Client(ll.MustClient()).MustConnect()
fmt.Println(
anotherBrowser.MustPage("https://go-rod.github.io").MustEval("() => document.title"),
)
utils.Pause()
}