-
-
Notifications
You must be signed in to change notification settings - Fork 332
/
main.go
38 lines (29 loc) · 1.13 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
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 beginers, run the below to start a launcher.Manager:
//
// docker run -p 7317:7317 ghcr.io/go-rod/rod
//
// 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.Client()).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"),
)
utils.Pause()
}