-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwindows.go
34 lines (30 loc) · 1.01 KB
/
windows.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
package biloba
import (
"github.com/chromedp/chromedp"
)
/*
SetWindowSize() sets the window size for this tab. A DeferCleanup is automatically registered to reset the window size after the spec ends
*/
func (b *Biloba) SetWindowSize(width, height int, opts ...chromedp.EmulateViewportOption) {
originalWidth, originalHeight := b.WindowSize()
b.gt.Helper()
err := chromedp.Run(b.Context, chromedp.EmulateViewport(int64(width), int64(height), opts...))
if err != nil {
b.gt.Fatalf("failed to set window size: %s", err.Error())
}
b.gt.DeferCleanup(func() {
err := chromedp.Run(b.Context, chromedp.EmulateViewport(int64(originalWidth), int64(originalHeight), chromedp.EmulatePortrait))
if err != nil {
b.gt.Fatalf("failed to reset window size: %s", err.Error())
}
})
}
/*
WindowSize() returns the current window size of this tab.
*/
func (b *Biloba) WindowSize() (int, int) {
b.gt.Helper()
var dimensions []int
b.Run(`[window.innerWidth, window.innerHeight]`, &dimensions)
return dimensions[0], dimensions[1]
}