4
4
"fmt"
5
5
"reflect"
6
6
7
- "github.com/dop251/goja "
7
+ "github.com/grafana/sobek "
8
8
9
9
"github.com/grafana/xk6-browser/common"
10
10
"github.com/grafana/xk6-browser/k6error"
@@ -15,30 +15,30 @@ import (
15
15
func mapBrowserContext (vu moduleVU , bc * common.BrowserContext ) mapping { //nolint:funlen,gocognit,cyclop
16
16
rt := vu .Runtime ()
17
17
return mapping {
18
- "addCookies" : func (cookies []* common.Cookie ) * goja .Promise {
18
+ "addCookies" : func (cookies []* common.Cookie ) * sobek .Promise {
19
19
return k6ext .Promise (vu .Context (), func () (any , error ) {
20
20
return nil , bc .AddCookies (cookies ) //nolint:wrapcheck
21
21
})
22
22
},
23
- "addInitScript" : func (script goja .Value ) * goja .Promise {
23
+ "addInitScript" : func (script sobek .Value ) * sobek .Promise {
24
24
return k6ext .Promise (vu .Context (), func () (any , error ) {
25
- if ! gojaValueExists (script ) {
25
+ if ! sobekValueExists (script ) {
26
26
return nil , nil
27
27
}
28
28
29
29
source := ""
30
30
switch script .ExportType () {
31
31
case reflect .TypeOf (string ("" )):
32
32
source = script .String ()
33
- case reflect .TypeOf (goja .Object {}):
33
+ case reflect .TypeOf (sobek .Object {}):
34
34
opts := script .ToObject (rt )
35
35
for _ , k := range opts .Keys () {
36
36
if k == "content" {
37
37
source = opts .Get (k ).String ()
38
38
}
39
39
}
40
40
default :
41
- _ , isCallable := goja .AssertFunction (script )
41
+ _ , isCallable := sobek .AssertFunction (script )
42
42
if ! isCallable {
43
43
source = fmt .Sprintf ("(%s);" , script .ToString ().String ())
44
44
} else {
@@ -53,27 +53,27 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin
53
53
// the browser is grabbed from VU.
54
54
return mapBrowser (vu )
55
55
},
56
- "clearCookies" : func () * goja .Promise {
56
+ "clearCookies" : func () * sobek .Promise {
57
57
return k6ext .Promise (vu .Context (), func () (any , error ) {
58
58
return nil , bc .ClearCookies () //nolint:wrapcheck
59
59
})
60
60
},
61
- "clearPermissions" : func () * goja .Promise {
61
+ "clearPermissions" : func () * sobek .Promise {
62
62
return k6ext .Promise (vu .Context (), func () (any , error ) {
63
63
return nil , bc .ClearPermissions () //nolint:wrapcheck
64
64
})
65
65
},
66
- "close" : func () * goja .Promise {
66
+ "close" : func () * sobek .Promise {
67
67
return k6ext .Promise (vu .Context (), func () (any , error ) {
68
68
return nil , bc .Close () //nolint:wrapcheck
69
69
})
70
70
},
71
- "cookies" : func (urls ... string ) * goja .Promise {
71
+ "cookies" : func (urls ... string ) * sobek .Promise {
72
72
return k6ext .Promise (vu .Context (), func () (any , error ) {
73
73
return bc .Cookies (urls ... ) //nolint:wrapcheck
74
74
})
75
75
},
76
- "grantPermissions" : func (permissions []string , opts goja .Value ) * goja .Promise {
76
+ "grantPermissions" : func (permissions []string , opts sobek .Value ) * sobek .Promise {
77
77
return k6ext .Promise (vu .Context (), func () (any , error ) {
78
78
popts := common .NewGrantPermissionsOptions ()
79
79
popts .Parse (vu .Context (), opts )
@@ -83,22 +83,22 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin
83
83
},
84
84
"setDefaultNavigationTimeout" : bc .SetDefaultNavigationTimeout ,
85
85
"setDefaultTimeout" : bc .SetDefaultTimeout ,
86
- "setGeolocation" : func (geolocation goja .Value ) * goja .Promise {
86
+ "setGeolocation" : func (geolocation sobek .Value ) * sobek .Promise {
87
87
return k6ext .Promise (vu .Context (), func () (any , error ) {
88
88
return nil , bc .SetGeolocation (geolocation ) //nolint:wrapcheck
89
89
})
90
90
},
91
- "setHTTPCredentials" : func (httpCredentials goja .Value ) * goja .Promise {
91
+ "setHTTPCredentials" : func (httpCredentials sobek .Value ) * sobek .Promise {
92
92
return k6ext .Promise (vu .Context (), func () (any , error ) {
93
93
return nil , bc .SetHTTPCredentials (httpCredentials ) //nolint:staticcheck,wrapcheck
94
94
})
95
95
},
96
- "setOffline" : func (offline bool ) * goja .Promise {
96
+ "setOffline" : func (offline bool ) * sobek .Promise {
97
97
return k6ext .Promise (vu .Context (), func () (any , error ) {
98
98
return nil , bc .SetOffline (offline ) //nolint:wrapcheck
99
99
})
100
100
},
101
- "waitForEvent" : func (event string , optsOrPredicate goja .Value ) (* goja .Promise , error ) {
101
+ "waitForEvent" : func (event string , optsOrPredicate sobek .Value ) (* sobek .Promise , error ) {
102
102
ctx := vu .Context ()
103
103
popts := common .NewWaitForEventOptions (
104
104
bc .Timeout (),
@@ -120,7 +120,7 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin
120
120
// before returning the result to the caller.
121
121
c := make (chan bool )
122
122
tq .Queue (func () error {
123
- var resp goja .Value
123
+ var resp sobek .Value
124
124
resp , err = popts .PredicateFn (vu .Runtime ().ToValue (p ))
125
125
rtn = resp .ToBoolean ()
126
126
close (c )
@@ -145,7 +145,7 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin
145
145
return mapPage (vu , p ), nil
146
146
}), nil
147
147
},
148
- "pages" : func () * goja .Object {
148
+ "pages" : func () * sobek .Object {
149
149
var (
150
150
mpages []mapping
151
151
pages = bc .Pages ()
@@ -160,7 +160,7 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin
160
160
161
161
return rt .ToValue (mpages ).ToObject (rt )
162
162
},
163
- "newPage" : func () * goja .Promise {
163
+ "newPage" : func () * sobek .Promise {
164
164
return k6ext .Promise (vu .Context (), func () (any , error ) {
165
165
page , err := bc .NewPage ()
166
166
if err != nil {
0 commit comments