Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit b8d958a

Browse files
committed
Map browserContext to Goja
1 parent 57bb477 commit b8d958a

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

browser/mapping.go

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,51 @@ func mapBrowserToGoja(vu k6modules.VU) *goja.Object {
4040
return obj
4141
}
4242

43+
// mapBrowserContext to the JS module.
44+
func mapBrowserContext(rt *goja.Runtime, bc api.BrowserContext) mapping {
45+
_ = rt
46+
return mapping{
47+
"addCookies": bc.AddCookies,
48+
"addInitScript": bc.AddInitScript,
49+
"browser": bc.Browser,
50+
"clearCookies": bc.ClearCookies,
51+
"clearPermissions": bc.ClearPermissions,
52+
"close": bc.Close,
53+
"cookies": bc.Cookies,
54+
"exposeBinding": bc.ExposeBinding,
55+
"exposeFunction": bc.ExposeFunction,
56+
"grantPermissions": bc.GrantPermissions,
57+
"newCDPSession": bc.NewCDPSession,
58+
"route": bc.Route,
59+
"setDefaultNavigationTimeout": bc.SetDefaultNavigationTimeout,
60+
"setDefaultTimeout": bc.SetDefaultTimeout,
61+
"setExtraHTTPHeaders": bc.SetExtraHTTPHeaders,
62+
"setGeolocation": bc.SetGeolocation,
63+
"setHTTPCredentials": bc.SetHTTPCredentials, //nolint:staticcheck
64+
"setOffline": bc.SetOffline,
65+
"storageState": bc.StorageState,
66+
"unroute": bc.Unroute,
67+
"waitForEvent": bc.WaitForEvent,
68+
"pages": bc.Pages,
69+
"newPage": bc.NewPage,
70+
}
71+
}
72+
4373
// mapBrowser to the JS module.
4474
func mapBrowser(rt *goja.Runtime, b api.Browser) mapping {
45-
_ = rt
4675
return mapping{
4776
"close": b.Close,
4877
"contexts": b.Contexts,
4978
"isConnected": b.IsConnected,
5079
"on": b.On,
5180
"userAgent": b.UserAgent,
5281
"version": b.Version,
53-
"newContext": b.NewContext,
54-
"newPage": b.NewPage,
82+
"newContext": func(opts goja.Value) *goja.Object {
83+
bctx := b.NewContext(opts)
84+
m := mapBrowserContext(rt, bctx)
85+
return rt.ToValue(m).ToObject(rt)
86+
},
87+
"newPage": b.NewPage,
5588
}
5689
}
5790

0 commit comments

Comments
 (0)