@@ -26,6 +26,7 @@ import (
26
26
"fmt"
27
27
"os"
28
28
"regexp"
29
+ "runtime"
29
30
30
31
"github.com/dop251/goja"
31
32
"github.com/grafana/xk6-browser/api"
@@ -85,47 +86,7 @@ func (b *BrowserType) Launch(opts goja.Value) api.Browser {
85
86
envs = append (envs , fmt .Sprintf ("%s=%s" , k , v ))
86
87
}
87
88
88
- flags := map [string ]interface {}{
89
- //chromedp.ProxyServer(""),
90
- //chromedp.UserAgent(""),
91
- //chromedp.UserDataDir(""),
92
- //chromedp.DisableGPU,
93
-
94
- "no-first-run" : true ,
95
- "no-default-browser-check" : true ,
96
- "no-sandbox" : true ,
97
- "headless" : launchOpts .Headless ,
98
- "auto-open-devtools-for-tabs" : launchOpts .Devtools ,
99
- "window-size" : fmt .Sprintf ("%d,%d" , 800 , 600 ),
100
-
101
- // After Puppeteer's and Playwright's default behavior.
102
- "disable-background-networking" : true ,
103
- "enable-features" : "NetworkService,NetworkServiceInProcess" ,
104
- "disable-background-timer-throttling" : true ,
105
- "disable-backgrounding-occluded-windows" : true ,
106
- "disable-breakpad" : true ,
107
- "disable-client-side-phishing-detection" : true ,
108
- "disable-component-extensions-with-background-pages" : true ,
109
- "disable-default-apps" : true ,
110
- "disable-dev-shm-usage" : true ,
111
- "disable-extensions" : true ,
112
- "disable-features" : "TranslateUI,BlinkGenPropertyTrees,ImprovedCookieControls,SameSiteByDefaultCookies,LazyFrameLoading" ,
113
- "disable-hang-monitor" : true ,
114
- "disable-ipc-flooding-protection" : true ,
115
- "disable-popup-blocking" : true ,
116
- "disable-prompt-on-repost" : true ,
117
- "disable-renderer-backgrounding" : true ,
118
- "disable-sync" : true ,
119
- "force-color-profile" : "srgb" ,
120
- "metrics-recording-only" : true ,
121
- "safebrowsing-disable-auto-update" : true ,
122
- "enable-automation" : true ,
123
- "password-store" : "basic" ,
124
- "use-mock-keychain" : true ,
125
- "no-startup-window" : true ,
126
- }
127
-
128
- allocator := NewAllocator (flags , envs )
89
+ allocator := NewAllocator (b .flags (launchOpts ), envs )
129
90
browserProc , err := allocator .Allocate (b .Ctx , launchOpts )
130
91
if browserProc == nil {
131
92
k6common .Throw (rt , fmt .Errorf ("cannot allocate browser: %w" , err ))
@@ -158,6 +119,53 @@ func (b *BrowserType) Name() string {
158
119
return "chromium"
159
120
}
160
121
122
+ func (b * BrowserType ) flags (lopts * common.LaunchOptions ) map [string ]interface {} {
123
+ // After Puppeteer's and Playwright's default behavior.
124
+ f := map [string ]interface {}{
125
+ "disable-background-networking" : true ,
126
+ "enable-features" : "NetworkService,NetworkServiceInProcess" ,
127
+ "disable-background-timer-throttling" : true ,
128
+ "disable-backgrounding-occluded-windows" : true ,
129
+ "disable-breakpad" : true ,
130
+ "disable-client-side-phishing-detection" : true ,
131
+ "disable-component-extensions-with-background-pages" : true ,
132
+ "disable-default-apps" : true ,
133
+ "disable-dev-shm-usage" : true ,
134
+ "disable-extensions" : true ,
135
+ "disable-features" : "ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,AcceptCHFrame" ,
136
+ "disable-hang-monitor" : true ,
137
+ "disable-ipc-flooding-protection" : true ,
138
+ "disable-popup-blocking" : true ,
139
+ "disable-prompt-on-repost" : true ,
140
+ "disable-renderer-backgrounding" : true ,
141
+ "disable-sync" : true ,
142
+ "force-color-profile" : "srgb" ,
143
+ "metrics-recording-only" : true ,
144
+ "no-first-run" : true ,
145
+ "safebrowsing-disable-auto-update" : true ,
146
+ "enable-automation" : true ,
147
+ "password-store" : "basic" ,
148
+ "use-mock-keychain" : true ,
149
+ "no-service-autorun" : true ,
150
+
151
+ "no-startup-window" : true ,
152
+ "no-default-browser-check" : true ,
153
+ "no-sandbox" : true ,
154
+ "headless" : lopts .Headless ,
155
+ "auto-open-devtools-for-tabs" : lopts .Devtools ,
156
+ "window-size" : fmt .Sprintf ("%d,%d" , 800 , 600 ),
157
+ }
158
+ if runtime .GOOS == "darwin" {
159
+ f ["enable-use-zoom-for-dsf" ] = false
160
+ }
161
+ if lopts .Headless {
162
+ f ["hide-scrollbars" ] = true
163
+ f ["mute-audio" ] = true
164
+ f ["blink-settings" ] = "primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4"
165
+ }
166
+ return f
167
+ }
168
+
161
169
// makes an extension wide logger
162
170
func makeLogger (ctx context.Context , launchOpts * common.LaunchOptions ) (* common.Logger , error ) {
163
171
var (
0 commit comments