@@ -77,7 +77,7 @@ func (b *BrowserContext) AddCookies(cookies goja.Value) {
77
77
78
78
// AddInitScript adds a script that will be initialized on all new pages.
79
79
func (b * BrowserContext ) AddInitScript (script goja.Value , arg goja.Value ) {
80
- b .logger .Debugf ("BrowserContext:AddInitScript" , "" )
80
+ b .logger .Debugf ("BrowserContext:AddInitScript" , "bctxid:%v" , b . id )
81
81
82
82
rt := k6common .GetRuntime (b .ctx )
83
83
@@ -118,6 +118,8 @@ func (b *BrowserContext) Browser() api.Browser {
118
118
119
119
// ClearCookies clears cookies.
120
120
func (b * BrowserContext ) ClearCookies () {
121
+ b .logger .Debugf ("BrowserContext:ClearCookies" , "bctxid:%v" , b .id )
122
+
121
123
action := storage .ClearCookies ().WithBrowserContextID (b .id )
122
124
if err := action .Do (b .ctx ); err != nil {
123
125
k6Throw (b .ctx , "unable to clear cookies permissions: %w" , err )
@@ -126,6 +128,8 @@ func (b *BrowserContext) ClearCookies() {
126
128
127
129
// ClearPermissions clears any permission overrides.
128
130
func (b * BrowserContext ) ClearPermissions () {
131
+ b .logger .Debugf ("BrowserContext:ClearPermissions" , "bctxid:%v" , b .id )
132
+
129
133
action := cdpbrowser .ResetPermissions ().WithBrowserContextID (b .id )
130
134
if err := action .Do (b .ctx ); err != nil {
131
135
k6Throw (b .ctx , "unable to clear override permissions: %w" , err )
@@ -134,6 +138,8 @@ func (b *BrowserContext) ClearPermissions() {
134
138
135
139
// Close shuts down the browser context.
136
140
func (b * BrowserContext ) Close () {
141
+ b .logger .Debugf ("BrowserContext:Close" , "bctxid:%v" , b .id )
142
+
137
143
if b .id == "" {
138
144
k6Throw (b .ctx , "default browser context can't be closed" )
139
145
}
@@ -157,7 +163,8 @@ func (b *BrowserContext) ExposeFunction(name string, callback goja.Callable) {
157
163
158
164
// GrantPermissions enables the specified permissions, all others will be disabled.
159
165
func (b * BrowserContext ) GrantPermissions (permissions []string , opts goja.Value ) {
160
- b .logger .Debugf ("BrowserContext:GrantPermissions" , "" )
166
+ b .logger .Debugf ("BrowserContext:GrantPermissions" , "bctxid:%v" , b .id )
167
+
161
168
permsToProtocol := map [string ]cdpbrowser.PermissionType {
162
169
"geolocation" : cdpbrowser .PermissionTypeGeolocation ,
163
170
"midi" : cdpbrowser .PermissionTypeMidi ,
@@ -232,11 +239,15 @@ func (b *BrowserContext) Route(url goja.Value, handler goja.Callable) {
232
239
233
240
// SetDefaultNavigationTimeout sets the default navigation timeout in milliseconds.
234
241
func (b * BrowserContext ) SetDefaultNavigationTimeout (timeout int64 ) {
242
+ b .logger .Debugf ("BrowserContext:SetDefaultNavigationTimeout" , "bctxid:%v timeout:%d" , b .id , timeout )
243
+
235
244
b .timeoutSettings .setDefaultNavigationTimeout (timeout )
236
245
}
237
246
238
247
// SetDefaultTimeout sets the default maximum timeout in milliseconds.
239
248
func (b * BrowserContext ) SetDefaultTimeout (timeout int64 ) {
249
+ b .logger .Debugf ("BrowserContext:SetDefaultTimeout" , "bctxid:%v timeout:%d" , b .id , timeout )
250
+
240
251
b .timeoutSettings .setDefaultTimeout (timeout )
241
252
}
242
253
@@ -246,6 +257,8 @@ func (b *BrowserContext) SetExtraHTTPHeaders(headers map[string]string) {
246
257
247
258
// SetGeolocation overrides the geo location of the user.
248
259
func (b * BrowserContext ) SetGeolocation (geolocation goja.Value ) {
260
+ b .logger .Debugf ("BrowserContext:SetGeolocation" , "bctxid:%v" , b .id )
261
+
249
262
g := NewGeolocation ()
250
263
if err := g .Parse (b .ctx , geolocation ); err != nil {
251
264
k6Throw (b .ctx , "cannot parse geo location: %w" , err )
@@ -261,6 +274,8 @@ func (b *BrowserContext) SetGeolocation(geolocation goja.Value) {
261
274
262
275
// SetHTTPCredentials sets username/password credentials to use for HTTP authentication.
263
276
func (b * BrowserContext ) SetHTTPCredentials (httpCredentials goja.Value ) {
277
+ b .logger .Debugf ("BrowserContext:SetHTTPCredentials" , "bctxid:%v" , b .id )
278
+
264
279
c := NewCredentials ()
265
280
if err := c .Parse (b .ctx , httpCredentials ); err != nil {
266
281
k6Throw (b .ctx , "cannot set HTTP credentials: %w" , err )
@@ -274,6 +289,8 @@ func (b *BrowserContext) SetHTTPCredentials(httpCredentials goja.Value) {
274
289
275
290
// SetOffline toggles the browser's connectivity on/off.
276
291
func (b * BrowserContext ) SetOffline (offline bool ) {
292
+ b .logger .Debugf ("BrowserContext:SetOffline" , "bctxid:%v offline:%t" , b .id , offline )
293
+
277
294
b .opts .Offline = offline
278
295
for _ , p := range b .browser .getPages () {
279
296
p .updateOffline ()
@@ -289,8 +306,8 @@ func (b *BrowserContext) Unroute(url goja.Value, handler goja.Callable) {
289
306
}
290
307
291
308
func (b * BrowserContext ) WaitForEvent (event string , optsOrPredicate goja.Value ) interface {} {
292
- b .logger .Debugf ("BrowserContext:WaitForEvent" , "event:%q" , event )
293
309
// TODO: This public API needs Promise support (as return value) to be useful in JS!
310
+ b .logger .Debugf ("BrowserContext:WaitForEvent" , "bctxid:%v event:%q" , b .id , event )
294
311
295
312
rt := k6common .GetRuntime (b .ctx )
296
313
@@ -326,16 +343,16 @@ func (b *BrowserContext) WaitForEvent(event string, optsOrPredicate goja.Value)
326
343
ch := make (chan interface {})
327
344
328
345
go func () {
329
- b .logger .Debugf ("BrowserContext:WaitForEvent:go()" , "starts" )
330
- defer b .logger .Debugf ("BrowserContext:WaitForEvent:go()" , "returns" )
346
+ b .logger .Debugf ("BrowserContext:WaitForEvent:go():starts " , "bctxid:%v" , b . id )
347
+ defer b .logger .Debugf ("BrowserContext:WaitForEvent:go():returns " , "bctxid:%v" , b . id )
331
348
for {
332
349
select {
333
350
case <- evCancelCtx .Done ():
334
- b .logger .Debugf ("BrowserContext:WaitForEvent:go()" , "evCancelCtx done" )
351
+ b .logger .Debugf ("BrowserContext:WaitForEvent:go():evCancelCtx:done " , "bctxid:%v" , b . id )
335
352
return
336
353
case ev := <- chEvHandler :
337
354
if ev .typ == EventBrowserContextClose {
338
- b .logger .Debugf ("BrowserContext:WaitForEvent:go()" , "EventBrowserContextClose returns" )
355
+ b .logger .Debugf ("BrowserContext:WaitForEvent:go():EventBrowserContextClose:return " , "bctxid:%v" , b . id )
339
356
ch <- nil
340
357
close (ch )
341
358
@@ -345,11 +362,11 @@ func (b *BrowserContext) WaitForEvent(event string, optsOrPredicate goja.Value)
345
362
return
346
363
}
347
364
if ev .typ == EventBrowserContextPage {
348
- b .logger .Debugf ("BrowserContext:WaitForEvent:go()" , "EventBrowserContextPage" )
365
+ b .logger .Debugf ("BrowserContext:WaitForEvent:go():EventBrowserContextPage " , "bctxid:%v" , b . id )
349
366
p := ev .data .(* Page )
350
367
exported := k6common .Bind (rt , p , & b .ctx )
351
368
if retVal , err := predicateFn (rt .ToValue (exported )); err == nil && retVal .ToBoolean () {
352
- b .logger .Debugf ("BrowserContext:WaitForEvent:go()" , "EventBrowserContextPage returns" )
369
+ b .logger .Debugf ("BrowserContext:WaitForEvent:go():EventBrowserContextPage:return " , "bctxid:%v" , b . id )
353
370
ch <- p
354
371
close (ch )
355
372
@@ -368,13 +385,13 @@ func (b *BrowserContext) WaitForEvent(event string, optsOrPredicate goja.Value)
368
385
369
386
select {
370
387
case <- b .ctx .Done ():
371
- b .logger .Debugf ("BrowserContext:WaitForEvent" , "b.ctx Done" )
388
+ b .logger .Debugf ("BrowserContext:WaitForEvent:ctx.Done " , "bctxid:%v event:%q" , b . id , event )
372
389
case <- time .After (timeout ):
373
- b .logger .Debugf ("BrowserContext:WaitForEvent" , "timeout" )
390
+ b .logger .Debugf ("BrowserContext:WaitForEvent:timeout " , "bctxid:%v event:%q" , b . id , event )
374
391
case evData := <- ch :
375
- b .logger .Debugf ("BrowserContext:WaitForEvent" , "evData" )
392
+ b .logger .Debugf ("BrowserContext:WaitForEvent:evData " , "bctxid:%v event:%q" , b . id , event )
376
393
return evData
377
394
}
378
- b .logger .Debugf ("BrowserContext:WaitForEvent" , "nil return" )
395
+ b .logger .Debugf ("BrowserContext:WaitForEvent:return nil " , "bctxid:%v event:%q" , b . id , event )
379
396
return nil
380
397
}
0 commit comments