You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: browsers-pages.md
+7-3
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,7 @@ To launch multiple browsers:
9
9
```go
10
10
browser1:= rod.New().MustConnect()
11
11
browser2:= rod.New().MustConnect()
12
+
fmt.Println(browser1, browser2)
12
13
```
13
14
14
15
All APIs are thread-safe, same works for multiple Go routines.
@@ -18,18 +19,20 @@ You can also use incognito mode to launch multiple browsers:
18
19
```go
19
20
browser1:= rod.New().MustConnect()
20
21
browser2:= browser1.MustIncognito()
22
+
fmt.Println(browser1, browser2)
21
23
```
22
24
23
25
Launch browsers with different launch arguments:
24
26
25
27
```go
26
28
browser1:= rod.New().ControlURL(
27
-
launcher.New().Headless(false).MustLaunch()
29
+
launcher.New().Headless(false).MustLaunch(),
28
30
).MustConnect()
29
31
30
-
browser1:= rod.New().ControlURL(
31
-
launcher.New().UserDataDir("path").MustLaunch()
32
+
browser2:= rod.New().ControlURL(
33
+
launcher.New().UserDataDir("path").MustLaunch(),
32
34
).MustConnect()
35
+
fmt.Println(browser1, browser2)
33
36
```
34
37
35
38
## Multiple pages
@@ -40,6 +43,7 @@ To launch multiple pages for a browser:
40
43
browser:= rod.New().MustConnect()
41
44
page1:= browser.MustPage("http://a.com")
42
45
page2:= browser.MustPage("http://b.com")
46
+
fmt.Println(page1, page2)
43
47
```
44
48
45
49
If a browser already has several pages open and you don't have references to them, you can use [Browser.Pages()](https://pkg.go.dev/github.com/go-rod/rod#Browser.Pages) to get a [Pages](https://pkg.go.dev/github.com/go-rod/rod#Pages) struct which is a list of tabs and/or windows with several helpful methods attached, such as [Pages.Find()](https://pkg.go.dev/github.com/go-rod/rod#Pages.Find), [Pages.FindByURL()](https://pkg.go.dev/github.com/go-rod/rod#Pages.FindByURL), [Pages.First()](https://pkg.go.dev/github.com/go-rod/rod#Pages.First), etc. Once you get a reference to the page you want you can use [Page.Activate()](https://pkg.go.dev/github.com/go-rod/rod#Page.Activate) to focus it. If you are clicking a link opens a new page then you can use [Page.WaitOpen](https://pkg.go.dev/github.com/go-rod/rod#Page.WaitOpen) to grab a reference to the new window as soon as it is launched.
0 commit comments