Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge browser in k6 #4056

Open
wants to merge 3,059 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
3059 commits
Select commit Hold shift + click to select a range
4fca4e6
Update waitforfunction.js to async check
inancgumus Sep 27, 2024
d33f23b
Update example dispatch to await
inancgumus Sep 30, 2024
3acf0ff
Update example elementstate to await
inancgumus Sep 30, 2024
61857d2
Update example evaluate to await
inancgumus Sep 30, 2024
38ac33f
Update example fillform to await
inancgumus Sep 30, 2024
40e3cea
Update example getattribute to await
inancgumus Sep 30, 2024
aaf32e9
Update example pageon to await
inancgumus Sep 30, 2024
83496af
Update example querying to await
inancgumus Sep 30, 2024
a6e8f78
Update example shadowdom to await
inancgumus Sep 30, 2024
cc34feb
Update example waitforfunction to await
inancgumus Sep 30, 2024
577e169
Bump (deps): Bump go.k6.io/k6
dependabot[bot] Oct 1, 2024
8fce16a
Fix k6 process hang when using page.on
ankur22 Oct 1, 2024
c71bdb1
Add comment on existing taskqueue.close call.
ankur22 Oct 1, 2024
61d4228
Fix the team issue template
inancgumus Oct 2, 2024
e429a04
Add ControlOrMeta helper key
ankur22 Oct 4, 2024
b04af2b
Update test to work with dblClick
ankur22 Oct 4, 2024
50be4e4
Add missing test pages
ankur22 Oct 4, 2024
a3a36a4
Refactor sobek out of request.headerValue
ankur22 Oct 7, 2024
6049bed
Remove sobek from request.timing
ankur22 Oct 7, 2024
8206006
Remove sobek from keyboard.press
ankur22 Oct 7, 2024
89df807
Remove Sobek from keyboard.Press
ankur22 Oct 7, 2024
e992fbd
Add syncMapKeyboard
ankur22 Oct 7, 2024
09815eb
Remove sobek from connection.Close
ankur22 Oct 7, 2024
6d3fb2c
Remove the unused args from connection.Close
ankur22 Oct 7, 2024
b364519
Enhance waitForSelector js error message
inancgumus Oct 4, 2024
0c207e1
Refactor page.on to work with any
ankur22 Oct 2, 2024
c4ce0b8
Refactor page.on to allow for other event types
ankur22 Oct 2, 2024
370c156
Refactor event so that it is exported
ankur22 Oct 2, 2024
1c30981
Refactor page mapping to work with switch
ankur22 Oct 2, 2024
2bb8a8f
Add default case for page.on in mapping
ankur22 Oct 2, 2024
fe9e211
Add metric event
ankur22 Oct 2, 2024
5892800
Add exportedMetric
ankur22 Oct 2, 2024
60f7817
Add URLGroups type
ankur22 Oct 2, 2024
f186a27
Add metric mapping
ankur22 Oct 2, 2024
fcd1ea3
Add a grouping func to sobek runtime
ankur22 Oct 2, 2024
4bc8de3
Add a callback to GroupURLTag
ankur22 Oct 2, 2024
e012605
Use the callback to perform the matching test
ankur22 Oct 2, 2024
49cd0ce
Add synchronization and name propagation
ankur22 Oct 2, 2024
d3110fe
Add function to call the handlers
ankur22 Oct 2, 2024
d667f02
Add call URLGroupingName before emit of metrics
ankur22 Oct 2, 2024
9b6cf06
Fix network_manager_test.go test
ankur22 Oct 3, 2024
b3c14f5
Update web vital metric to retrieve name
ankur22 Oct 3, 2024
101da13
Add a test for page.on('metric')
ankur22 Oct 3, 2024
ed26cd9
Fix lint issue
ankur22 Oct 3, 2024
fa20705
Add an example for page.on('metric')
ankur22 Oct 3, 2024
51197b4
Rename urlGroupingName to unexport it
ankur22 Oct 3, 2024
745a551
Update URL and use any instead of interface{}
ankur22 Oct 4, 2024
9974a5b
Refactor to use atomic in TestPageOnMetric
ankur22 Oct 4, 2024
d8c2638
Fix name with strings.TrimSpace
ankur22 Oct 4, 2024
431f59e
Refactor url tagging into its own function
ankur22 Oct 4, 2024
947c4e1
Refactor mapMsgAndHandleEvent out
ankur22 Oct 4, 2024
ec7856f
Refactor how the name is returned back to caller
ankur22 Oct 4, 2024
042527b
Add summary for urlGroupingName
ankur22 Oct 4, 2024
92bf084
Remove a couple of locks and add a test
ankur22 Oct 4, 2024
001e8c1
Add comments on test
ankur22 Oct 4, 2024
20502bd
Rename groups to urls
ankur22 Oct 4, 2024
5a25939
Add regexCallback
ankur22 Oct 4, 2024
6b91b79
Rename groupURLTag to Tag
ankur22 Oct 4, 2024
2e9eff5
Rename msg to metric
ankur22 Oct 4, 2024
d444108
Rename urlGroupingName to urlTagName
ankur22 Oct 4, 2024
180f911
Rename to MetricEvent from ExportedMetric
ankur22 Oct 4, 2024
536ebee
Refactor MetricEvent out of loop
ankur22 Oct 7, 2024
0ba709b
Rename URLGroups to URLOverrides
ankur22 Oct 7, 2024
13abc6c
Rename type and fields
ankur22 Oct 7, 2024
2ccf482
Rename name and nameChanged
ankur22 Oct 7, 2024
70ccdea
Rename to _k6BrowserCheckRegEx
ankur22 Oct 7, 2024
fe0f161
Rename func type to k6BrowserCheckRegEx
ankur22 Oct 7, 2024
6fd0811
Rename to url from urlTag
ankur22 Oct 7, 2024
55e61a3
Rename val to matched
ankur22 Oct 7, 2024
67214db
Rename name to userProvidedTagName
ankur22 Oct 7, 2024
1ff7789
Use a bool to signal a match was found
ankur22 Oct 7, 2024
7cbe1b0
Update args onto new lines
ankur22 Oct 7, 2024
94e6971
Update test with t.Parallel()
ankur22 Oct 7, 2024
f6dd73c
Rename the JS fields back to url and name
ankur22 Oct 7, 2024
40f60ca
Update to the latest version of CDP
ankur22 Sep 27, 2024
4e1fba5
Update PostData to work with PostDataEntries
ankur22 Sep 27, 2024
7ed4b00
Add comment for postDataEntries
ankur22 Oct 8, 2024
7a4e6e9
Add tracing to page.waitForTimeout
ankur22 Oct 8, 2024
a30af07
Fix metric event tag method name
inancgumus Oct 9, 2024
5257878
Fix page.on mapping signature in test
inancgumus Oct 9, 2024
a342f7d
Export k6BrowserCheckRegEx
inancgumus Oct 9, 2024
ca24744
Add metricEventAPI mapping type
inancgumus Oct 9, 2024
667efa0
Add mapMetricEvent test
inancgumus Oct 9, 2024
8bf713f
Fix pageon metric example
inancgumus Oct 9, 2024
ab1c556
Move k6BrowserRegEx checker to page on mapping
inancgumus Oct 9, 2024
ebb1391
Improve page.on metric namings
inancgumus Oct 10, 2024
f9d9252
Fix MetricEvent.Tag input
inancgumus Oct 10, 2024
d6fefd3
Add PageOnEvent
inancgumus Oct 9, 2024
ad484b0
Refactor any to PageOnEvent
inancgumus Oct 9, 2024
57e1db0
Rename page on event a to event
inancgumus Oct 9, 2024
b680e2c
Rename page.on mapping
inancgumus Oct 9, 2024
206c2a8
Add PageOnEventName for type safety
inancgumus Oct 10, 2024
c0042e6
Use PageOnEvent name
inancgumus Oct 10, 2024
dab04d6
Remove page on event name check
inancgumus Oct 10, 2024
16a650a
Update page on mapping test to use PageOnEvent
inancgumus Oct 10, 2024
68cff64
Add a POC to retry waitFor until it is success
ankur22 Oct 8, 2024
75647e9
Add retry count for max waitFor call stack
ankur22 Oct 9, 2024
6ddebf9
Move pageOn mapping to a function
inancgumus Oct 10, 2024
5489038
Remove unnecessary vu.VU calls from mapPageOn
inancgumus Oct 10, 2024
cafed06
Move VU runtime to variable in mapPageOn
inancgumus Oct 10, 2024
f2528ab
Rename runInTaskQueue to mapHandler
inancgumus Oct 10, 2024
5a89562
Inline console API mapping closure
inancgumus Oct 10, 2024
be5f3ea
Extract page on console
inancgumus Oct 10, 2024
b5d4c63
Extract page on metric
inancgumus Oct 10, 2024
24e2a25
Refactor mapConsoleMessage to PageOnEvent
inancgumus Oct 10, 2024
8357a7d
Use cm variable in mapConsoleMessage
inancgumus Oct 10, 2024
f08046b
Refactor mapConsoleMessage out of sobek
inancgumus Oct 10, 2024
a786310
Refactor mapMetricevent to PageOnEvent
inancgumus Oct 10, 2024
7f99d54
Remove excessive VU call mapMetricEvent
inancgumus Oct 10, 2024
8833a2f
Use em variable in mapMetricEvent
inancgumus Oct 10, 2024
705086c
Extract err from mapMetricEvent call
inancgumus Oct 10, 2024
0dee7bc
Rename channel c to done
inancgumus Oct 10, 2024
305ec95
Rename event to eventName
inancgumus Oct 10, 2024
91ff150
Rename mapPageOn handler to handleEvent
inancgumus Oct 10, 2024
4ffe550
Add queueHandler to mapPageOn
inancgumus Oct 10, 2024
46ccf03
Refactor page on console
inancgumus Oct 10, 2024
17092c4
Refactor page on metric
inancgumus Oct 10, 2024
f006807
Move onEventPageConsoleAPICalled
inancgumus Oct 10, 2024
4bafc79
Move onEventPageMetricCalled
inancgumus Oct 10, 2024
76b6cda
Move _k6BrowserCheckRegEx
inancgumus Oct 10, 2024
366f14d
Add a map to validate unknown page on events
inancgumus Oct 10, 2024
c060516
Use pageOnEvents map to determine the event to map
inancgumus Oct 10, 2024
0099139
Use pageOnEvents to determine to wait
inancgumus Oct 10, 2024
7ad8ade
Use mapPageOn queueHandler
inancgumus Oct 10, 2024
06a411f
Add mapPageOn p.on explanation
inancgumus Oct 10, 2024
4d254ab
Move k6 browser regex checker to func
inancgumus Oct 10, 2024
a34d1a2
Add prep to pageOnEvents
inancgumus Oct 10, 2024
92bf427
Add k6BrowserRegExChecker to prep
inancgumus Oct 10, 2024
3ee9039
Use pageOnEvents prep if exists
inancgumus Oct 10, 2024
725f825
Refactor prepK6BrowserRegExChecker to put in map
inancgumus Oct 10, 2024
5daf078
Explain mapPageOn behavior
inancgumus Oct 10, 2024
c98da11
Move page on event mapping out of task queue
inancgumus Oct 11, 2024
096afd8
Improve mapPageOn naming
inancgumus Oct 11, 2024
f757283
Use pattern directly in k6BrowserCheckRegEx
inancgumus Oct 11, 2024
235fc72
Move page on events closer
inancgumus Oct 10, 2024
427cbbf
Remove unused context from url tag name
inancgumus Oct 10, 2024
b6b5921
Add hasPageOnHandler
inancgumus Oct 10, 2024
8d83a89
Rearrange urlTagName locks
inancgumus Oct 10, 2024
346cf13
Use hasPageOnHandler in onConsoleAPICalled
inancgumus Oct 10, 2024
5bdb2de
Remove unnecessary copying
inancgumus Oct 10, 2024
2cff454
Fix linter issue with MetricInterceptorMock
inancgumus Oct 10, 2024
58f9bc3
Fix memory leak in queue
ankur22 Oct 16, 2024
e0be11d
Update the name field on page.on metric API
ankur22 Oct 17, 2024
64bd4cd
Rename urls to matches
ankur22 Oct 17, 2024
5e37210
Update comment on urlTagName
ankur22 Oct 17, 2024
280656f
Rename the variable from patterns to matches
ankur22 Oct 17, 2024
8eb5683
Move the name error check outside for loop
ankur22 Oct 17, 2024
bb53cc6
Rename userProvidedTagName
ankur22 Oct 17, 2024
2700524
Add method argument to handleURLTag
ankur22 Oct 17, 2024
07055b8
Add method argument to urlTagName
ankur22 Oct 17, 2024
a509cf1
Add method to MetricEvent and assign it
ankur22 Oct 17, 2024
d14812a
Add method on Match type
ankur22 Oct 17, 2024
844224c
Add method validation
ankur22 Oct 17, 2024
9b2c00e
Add method comparison
ankur22 Oct 17, 2024
def41a9
Update page.on('metric') example
ankur22 Oct 17, 2024
aa5a9c4
Add a test to ensure tag works with method
ankur22 Oct 17, 2024
b90b48f
Add a test to showcase incorrect method
ankur22 Oct 17, 2024
59138b2
Add a test for when name is invalid
ankur22 Oct 17, 2024
4802639
Add a test to for when the method is invalid
ankur22 Oct 17, 2024
aedd78e
Add a test to ensure lowercase method works
ankur22 Oct 17, 2024
67d6dc8
Add context done case
ankur22 Oct 18, 2024
135e886
Add context done case to waitForEvent
ankur22 Oct 18, 2024
90b8cf7
Add a PageOnHandler type
ankur22 Oct 18, 2024
f332592
Add an error return value to PageOnHandler
ankur22 Oct 18, 2024
dce4487
Update page.on handler to return error
ankur22 Oct 18, 2024
2a04643
Add error handling on page.on(metric) handler
ankur22 Oct 18, 2024
18cbe37
Add err handling to page.on(console)
ankur22 Oct 18, 2024
a0fa724
Add browserContext.downloadsPath
inancgumus Oct 21, 2024
37ff724
Add browserContext.downloadsPath set
inancgumus Oct 21, 2024
bd99620
Add browserContext.downloadsPath test
inancgumus Oct 21, 2024
b6fb3b0
Add BrowserContext.DownloadsPath field
inancgumus Oct 21, 2024
565f70a
Add artifactsDirectory path
inancgumus Oct 21, 2024
0b2e27e
Add BrowserContext.setDownloadsPath
inancgumus Oct 21, 2024
4001f38
Add TestSetDownloadsPath.empty_path
inancgumus Oct 21, 2024
ac0281b
Add TestSetDownloadsPath.non_empty_path
inancgumus Oct 21, 2024
b86a59f
Add setting downloadsPath in NewBrowserContext
inancgumus Oct 21, 2024
943c568
Fix setDownloadsPath doc
inancgumus Oct 25, 2024
56449e9
Refactor promise helpers to fix Interrupt with async code
mstoykov Oct 25, 2024
a979027
Desobekify BrowserContext.SetGeolocation
inancgumus Nov 4, 2024
a1d4bc0
Update SetGeolocation mapping test
inancgumus Nov 4, 2024
f77f185
Refactor Geolocation.Parse
inancgumus Nov 4, 2024
a94dd45
Desobekify BrowserContext.SetHTTPCredentials
inancgumus Nov 4, 2024
53db24d
Update SetHTTPCredentials mapping test
inancgumus Nov 4, 2024
44fa0c0
Refactor Credentials.Parse
inancgumus Nov 4, 2024
173e100
Fix Geolocation.Accuracy
inancgumus Nov 4, 2024
2303d9c
Add TestBrowserContextSetGeolocation
inancgumus Nov 4, 2024
946e4cb
Desobekify BrowserContextOptionParsing
inancgumus Nov 4, 2024
4773396
Add exportTo helper
inancgumus Nov 5, 2024
ea41b9e
Refactor GrantPermissionOptions parsing to mapping
inancgumus Nov 4, 2024
fe02411
Add parseWaitForEventOptions
inancgumus Nov 5, 2024
d7bd994
Use browserContext.waitForEvent in mapping
inancgumus Nov 5, 2024
25b0fba
Use browserContext.waitForEvent in sync mapping
inancgumus Nov 5, 2024
9fddcd9
Remove WaitForEvent parsing in common
inancgumus Nov 5, 2024
d39abde
Add WaitForEventOptions to mapping
inancgumus Nov 5, 2024
5836d19
Use browser.WaitForEventOptions
inancgumus Nov 5, 2024
4634741
Remove common.WaitForEventOptions
inancgumus Nov 5, 2024
17dfb7f
Move SetGeolocation validation into business logic
inancgumus Nov 5, 2024
879dbbb
Use Sobek for Geolocation transformation
inancgumus Nov 5, 2024
ed1488e
Validate SetGeolocation geolocation
inancgumus Nov 5, 2024
2a7b64b
Use exportTo browser.geolocation
inancgumus Nov 5, 2024
c4b86d3
Add CODEOWNERS (#1528)
andrewslotin Nov 7, 2024
7a8ee0c
Migrate to k6 roadmap (#1529)
andrewslotin Nov 7, 2024
740dac8
Fix Sobek.Object.Get(key) *[]any issue
inancgumus Nov 6, 2024
151b982
Fix TestKeyboardPress panic
inancgumus Nov 6, 2024
3479f77
Rename to HTTPCredentials
inancgumus Nov 6, 2024
045a6ee
Use exportTo for browser HTTP credentials
inancgumus Nov 6, 2024
a3c6f49
Use exportTo for browserContext HTTP credentials
inancgumus Nov 6, 2024
e85e2a8
Remove NewCredentials and Parse
inancgumus Nov 6, 2024
51fe2db
Use Credentials as a value type
inancgumus Nov 6, 2024
d745970
Add Credentials.Empty
inancgumus Nov 6, 2024
b58904b
Use Credentials.IsEmpty
inancgumus Nov 6, 2024
3d4690f
Refactor Screen to value type
inancgumus Nov 6, 2024
b4edff5
Desobekify BrowserContext.Screen
inancgumus Nov 6, 2024
598e786
Remove Screen.Parse and constants
inancgumus Nov 6, 2024
306c535
Refactor Viewport to value type
inancgumus Nov 6, 2024
a987705
Rename calculateInset to recalculateInset
inancgumus Nov 6, 2024
e990565
Add Viewport.IsEmpty
inancgumus Nov 6, 2024
3726b49
Use Viewport.IsEmpty
inancgumus Nov 6, 2024
74057e0
Desobekify BrowserContext.Viewport
inancgumus Nov 6, 2024
7c9f9c1
Remove Viewport.parse
inancgumus Nov 6, 2024
5100b4a
Removes forgetten Geolocation.Parse
inancgumus Nov 6, 2024
b675030
Refactor KeyboardOptions to value type
inancgumus Nov 6, 2024
a0a0e05
Refactor browser keyboard mapping
inancgumus Nov 6, 2024
30850f2
Refactor browser keyboard sync mapping
inancgumus Nov 6, 2024
4b09c5f
Refactor elementhandle keyboard mapping
inancgumus Nov 6, 2024
c11fbad
Refactor frame keyboard mapping
inancgumus Nov 6, 2024
be2a913
Refactor keyboard tests
inancgumus Nov 6, 2024
daace5f
Remove NewKeyboardOptions
inancgumus Nov 6, 2024
147ec11
Refactor mapKeyboard.press to exportTo
inancgumus Nov 6, 2024
7abe780
Refactor mapKeyboard.type to exportTo
inancgumus Nov 6, 2024
25ddf95
Refactor syncMapKeyboard.press to exportTo
inancgumus Nov 6, 2024
f793eb6
Refactor syncMapKeyboard.type to exportTo
inancgumus Nov 6, 2024
2448493
Remove KeyboardOptions.Parse
inancgumus Nov 6, 2024
287d7a5
Move KeyboardOptions to keyboard.go
inancgumus Nov 6, 2024
dbd050f
Remove unused NetworkManager.ExtraHTTPHeaders
inancgumus Nov 6, 2024
7390743
Refactor parseBrowserContextOptions
inancgumus Nov 6, 2024
2b3df76
Refactor parseBrowserContextOptions to Sobek RT
inancgumus Nov 6, 2024
a87da04
Add mergeWith Sobek helper
inancgumus Nov 6, 2024
26a9eff
Use mergeWith parseBrowserContextOptions
inancgumus Nov 6, 2024
7ee71c5
Add TestBrowserContextDefaultOptions
inancgumus Nov 6, 2024
6e8c206
Rename to DefaultBrowserContextOptions
inancgumus Nov 7, 2024
5d6121e
Remove forgotten NewGeolocation
inancgumus Nov 7, 2024
a5ba0c4
Move Geolocation below
inancgumus Nov 7, 2024
946cb18
Add TestBrowserContextAllOptions
inancgumus Nov 7, 2024
e75e6f3
Bump (deps): Bump go.k6.io/k6 from 0.54.0 to 0.55.0
dependabot[bot] Nov 12, 2024
f381bee
Refactor waitFor so that it returns a handle
ankur22 Nov 11, 2024
1974b8a
Fix waitForSelector by calling waitFor
ankur22 Nov 11, 2024
3c906c4
Add 'js/modules/k6/browser/' from commit '1974b8a50abace6dabefd38b363…
mstoykov Nov 13, 2024
05fb20e
browser: cleanup unnsecessary files
mstoykov Nov 13, 2024
2b587dd
Move to using the in k6 browser code
mstoykov Nov 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ require (
github.com/go-sourcemap/sourcemap v2.1.4+incompatible
github.com/golang/protobuf v1.5.4
github.com/gorilla/websocket v1.5.3
github.com/grafana/xk6-browser v1.9.1
github.com/grafana/xk6-dashboard v0.7.5
github.com/grafana/xk6-output-opentelemetry v0.3.0
github.com/grafana/xk6-output-prometheus-remote v0.5.0
Expand Down Expand Up @@ -66,7 +65,7 @@ require (
github.com/bufbuild/protocompile v0.14.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/chromedp/cdproto v0.0.0-20240919203636-12af5e8a671f // indirect
github.com/chromedp/cdproto v0.0.0-20240919203636-12af5e8a671f
github.com/chromedp/sysutil v1.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
Expand Down Expand Up @@ -96,7 +95,7 @@ require (
go.opentelemetry.io/otel/metric v1.29.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.28.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sync v0.8.0
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240822170219-fc7c04adadcd // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/dlclark/regexp2 v1.11.4 h1:rPYF9/LECdNymJufQKmri9gV604RvvABwgOA8un7yAo=
github.com/dlclark/regexp2 v1.11.4/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/dop251/goja v0.0.0-20240610225006-393f6d42497b h1:fMKDnOAKCGXSZBphY/ilLtu7cmwMnjqE+xJxUkfkpCY=
github.com/dop251/goja v0.0.0-20240610225006-393f6d42497b/go.mod h1:o31y53rb/qiIAONF7w3FHJZRqqP3fzHUr1HqanthByw=
github.com/dop251/goja v0.0.0-20240516125602-ccbae20bcec2 h1:OFTHt+yJDo/uaIKMGjEKzc3DGhrpQZoqvMUIloZv6ZY=
github.com/dop251/goja v0.0.0-20240516125602-ccbae20bcec2/go.mod h1:o31y53rb/qiIAONF7w3FHJZRqqP3fzHUr1HqanthByw=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand Down Expand Up @@ -89,8 +89,6 @@ github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aN
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grafana/sobek v0.0.0-20241024150027-d91f02b05e9b h1:hzfIt1lf19Zx1jIYdeHvuWS266W+jL+7dxbpvH2PZMQ=
github.com/grafana/sobek v0.0.0-20241024150027-d91f02b05e9b/go.mod h1:FmcutBFPLiGgroH42I4/HBahv7GxVjODcVWFTw1ISes=
github.com/grafana/xk6-browser v1.9.1 h1:wmISbIbzl7JtmvpkbXKhUg3XtFPepN+fss6UupZyRW0=
github.com/grafana/xk6-browser v1.9.1/go.mod h1:c0wf9sUlUjbhCnwHUFf6tkgkpoh/AXMuVd21XXIhyWY=
github.com/grafana/xk6-dashboard v0.7.5 h1:TcILyffT/Ea/XD7xG1jMA5lwtusOPRbEQsQDHmO30Mk=
github.com/grafana/xk6-dashboard v0.7.5/go.mod h1:Y75F8xmgCraKT+pBzFH6me9AyH5PkXD+Bxo1dm6Il/M=
github.com/grafana/xk6-output-opentelemetry v0.3.0 h1:dmclGBFtFVRJijqLncpu2dKVIIvx1GS3y6sQGg4Khl8=
Expand Down
2 changes: 1 addition & 1 deletion js/jsmodules.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"go.k6.io/k6/js/common"
"go.k6.io/k6/js/modules"
"go.k6.io/k6/js/modules/k6"
"go.k6.io/k6/js/modules/k6/browser/browser"
"go.k6.io/k6/js/modules/k6/crypto"
"go.k6.io/k6/js/modules/k6/crypto/x509"
"go.k6.io/k6/js/modules/k6/data"
Expand All @@ -24,7 +25,6 @@ import (
"go.k6.io/k6/js/modules/k6/timers"
"go.k6.io/k6/js/modules/k6/ws"

"github.com/grafana/xk6-browser/browser"
"github.com/grafana/xk6-redis/redis"
"github.com/grafana/xk6-webcrypto/webcrypto"
expws "github.com/grafana/xk6-websockets/websockets"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"errors"
"fmt"
"reflect"
"time"

"github.com/grafana/sobek"

"github.com/grafana/xk6-browser/common"
"github.com/grafana/xk6-browser/k6error"
"github.com/grafana/xk6-browser/k6ext"
"go.k6.io/k6/js/modules/k6/browser/common"
"go.k6.io/k6/js/modules/k6/browser/k6error"
"go.k6.io/k6/js/modules/k6/browser/k6ext"
)

// mapBrowserContext to the JS module.
Expand Down Expand Up @@ -74,40 +75,47 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin
return bc.Cookies(urls...) //nolint:wrapcheck
})
},
"grantPermissions": func(permissions []string, opts sobek.Value) *sobek.Promise {
"grantPermissions": func(permissions []string, opts sobek.Value) (*sobek.Promise, error) {
popts, err := exportTo[common.GrantPermissionsOptions](vu.Runtime(), opts)
if err != nil {
return nil, fmt.Errorf("parsing grant permission options: %w", err)
}
return k6ext.Promise(vu.Context(), func() (any, error) {
popts := common.NewGrantPermissionsOptions()
popts.Parse(vu.Context(), opts)

return nil, bc.GrantPermissions(permissions, popts) //nolint:wrapcheck
})
return nil, bc.GrantPermissions(permissions, popts)
}), nil
},
"setDefaultNavigationTimeout": bc.SetDefaultNavigationTimeout,
"setDefaultTimeout": bc.SetDefaultTimeout,
"setGeolocation": func(geolocation sobek.Value) *sobek.Promise {
"setGeolocation": func(geolocation sobek.Value) (*sobek.Promise, error) {
gl, err := exportTo[common.Geolocation](vu.Runtime(), geolocation)
if err != nil {
return nil, fmt.Errorf("parsing geo location: %w", err)
}
return k6ext.Promise(vu.Context(), func() (any, error) {
return nil, bc.SetGeolocation(geolocation) //nolint:wrapcheck
})
return nil, bc.SetGeolocation(&gl)
}), nil
},
"setHTTPCredentials": func(httpCredentials sobek.Value) *sobek.Promise {
"setHTTPCredentials": func(httpCredentials sobek.Value) (*sobek.Promise, error) {
creds, err := exportTo[common.Credentials](rt, httpCredentials)
if err != nil {
return nil, fmt.Errorf("parsing HTTP credentials: %w", err)
}
return k6ext.Promise(vu.Context(), func() (any, error) {
return nil, bc.SetHTTPCredentials(httpCredentials) //nolint:staticcheck,wrapcheck
})
return nil, bc.SetHTTPCredentials(creds) //nolint:staticcheck
}), nil
},
"setOffline": func(offline bool) *sobek.Promise {
return k6ext.Promise(vu.Context(), func() (any, error) {
return nil, bc.SetOffline(offline) //nolint:wrapcheck
})
},
"waitForEvent": func(event string, optsOrPredicate sobek.Value) (*sobek.Promise, error) {
ctx := vu.Context()
popts := common.NewWaitForEventOptions(
bc.Timeout(),
)
if err := popts.Parse(ctx, optsOrPredicate); err != nil {
return nil, fmt.Errorf("parsing waitForEvent options: %w", err)
popts, err := parseWaitForEventOptions(vu.Runtime(), optsOrPredicate, bc.Timeout())
if err != nil {
return nil, fmt.Errorf("parsing wait for event options: %w", err)
}

ctx := vu.Context()
return k6ext.Promise(ctx, func() (result any, reason error) {
var runInTaskQueue func(p *common.Page) (bool, error)
if popts.PredicateFn != nil {
Expand Down Expand Up @@ -177,3 +185,48 @@ func mapBrowserContext(vu moduleVU, bc *common.BrowserContext) mapping { //nolin
},
}
}

// waitForEventOptions are the options used by the browserContext.waitForEvent API.
type waitForEventOptions struct {
Timeout time.Duration
PredicateFn sobek.Callable
}

// parseWaitForEventOptions parses optsOrPredicate into a WaitForEventOptions.
// It returns a WaitForEventOptions with the default timeout if optsOrPredicate is nil,
// or not a callable predicate function.
// It can parse only a callable predicate function or an object which contains a
// callable predicate function and a timeout.
func parseWaitForEventOptions(
rt *sobek.Runtime, optsOrPredicate sobek.Value, defaultTime time.Duration,
) (*waitForEventOptions, error) {
w := &waitForEventOptions{
Timeout: defaultTime,
}

if !sobekValueExists(optsOrPredicate) {
return w, nil
}
var isCallable bool
w.PredicateFn, isCallable = sobek.AssertFunction(optsOrPredicate)
if isCallable {
return w, nil
}

opts := optsOrPredicate.ToObject(rt)
for _, k := range opts.Keys() {
switch k {
case "predicate":
w.PredicateFn, isCallable = sobek.AssertFunction(opts.Get(k))
if !isCallable {
return nil, errors.New("predicate function is not callable")
}
case "timeout":
w.Timeout = time.Duration(opts.Get(k).ToInteger()) * time.Millisecond
default:
return nil, fmt.Errorf("unknown option: %s", k)
}
}

return w, nil
}
136 changes: 136 additions & 0 deletions js/modules/k6/browser/browser/browser_context_options_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package browser

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.k6.io/k6/js/modules/k6/browser/common"
"go.k6.io/k6/js/modules/k6/browser/k6ext/k6test"
)

func TestBrowserContextOptionsPermissions(t *testing.T) {
vu := k6test.NewVU(t)

opts, err := parseBrowserContextOptions(vu.Runtime(), vu.ToSobekValue((struct {
Permissions []any `js:"permissions"`
}{
Permissions: []any{"camera", "microphone"},
})))
assert.NoError(t, err)
assert.Len(t, opts.Permissions, 2)
assert.Equal(t, opts.Permissions, []string{"camera", "microphone"})
}

func TestBrowserContextSetGeolocation(t *testing.T) {
vu := k6test.NewVU(t)

opts, err := parseBrowserContextOptions(vu.Runtime(), vu.ToSobekValue((struct {
GeoLocation *common.Geolocation `js:"geolocation"`
}{
GeoLocation: &common.Geolocation{
Latitude: 1.0,
Longitude: 2.0,
Accuracy: 3.0,
},
})))
assert.NoError(t, err)
assert.NotNil(t, opts)
assert.Equal(t, 1.0, opts.Geolocation.Latitude)
assert.Equal(t, 2.0, opts.Geolocation.Longitude)
assert.Equal(t, 3.0, opts.Geolocation.Accuracy)
}

func TestBrowserContextDefaultOptions(t *testing.T) {
vu := k6test.NewVU(t)

defaults := common.DefaultBrowserContextOptions()

// gets the default options by default
opts, err := parseBrowserContextOptions(vu.Runtime(), nil)
require.NoError(t, err)
assert.Equal(t, defaults, opts)

// merges with the default options
opts, err = parseBrowserContextOptions(vu.Runtime(), vu.ToSobekValue((struct {
DeviceScaleFactor float64 `js:"deviceScaleFactor"` // just to test a different field
}{
DeviceScaleFactor: defaults.DeviceScaleFactor + 1,
})))
require.NoError(t, err)
assert.NotEqual(t, defaults.DeviceScaleFactor, opts.DeviceScaleFactor)
assert.Equal(t, defaults.Locale, opts.Locale) // should remain as default
}

func TestBrowserContextAllOptions(t *testing.T) {
vu := k6test.NewVU(t)
opts, err := vu.Runtime().RunString(`const opts = {
acceptDownloads: true,
downloadsPath: '/tmp',
bypassCSP: true,
colorScheme: 'dark',
deviceScaleFactor: 1,
extraHTTPHeaders: {
'X-Header': 'value',
},
geolocation: { latitude: 51.509865, longitude: -0.118092, accuracy: 1 },
hasTouch: true,
httpCredentials: { username: 'admin', password: 'password' },
ignoreHTTPSErrors: true,
isMobile: true,
javaScriptEnabled: true,
locale: 'fr-FR',
offline: true,
permissions: ['camera', 'microphone'],
reducedMotion: 'no-preference',
screen: { width: 800, height: 600 },
timezoneID: 'Europe/Paris',
userAgent: 'my agent',
viewport: { width: 800, height: 600 },
};
opts;
`)
require.NoError(t, err)

parsedOpts, err := parseBrowserContextOptions(vu.Runtime(), opts)
require.NoError(t, err)

assert.Equal(t, &common.BrowserContextOptions{
AcceptDownloads: true,
DownloadsPath: "/tmp",
BypassCSP: true,
ColorScheme: common.ColorSchemeDark,
DeviceScaleFactor: 1,
ExtraHTTPHeaders: map[string]string{
"X-Header": "value",
},
Geolocation: &common.Geolocation{
Latitude: 51.509865,
Longitude: -0.118092,
Accuracy: 1,
},
HasTouch: true,
HTTPCredentials: common.Credentials{
Username: "admin",
Password: "password",
},
IgnoreHTTPSErrors: true,
IsMobile: true,
JavaScriptEnabled: true,
Locale: "fr-FR",
Offline: true,
Permissions: []string{"camera", "microphone"},
ReducedMotion: common.ReducedMotionNoPreference,
Screen: common.Screen{
Width: 800,
Height: 600,
},
TimezoneID: "Europe/Paris",
UserAgent: "my agent",
Viewport: common.Viewport{
Width: 800,
Height: 600,
},
}, parsedOpts)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (

"github.com/grafana/sobek"

"github.com/grafana/xk6-browser/common"
"github.com/grafana/xk6-browser/k6ext"
"go.k6.io/k6/js/modules/k6/browser/common"
"go.k6.io/k6/js/modules/k6/browser/k6ext"
)

// mapBrowser to the JS module.
Expand Down Expand Up @@ -36,8 +36,8 @@ func mapBrowser(vu moduleVU) mapping { //nolint:funlen,cyclop,gocognit
return b.IsConnected(), nil
},
"newContext": func(opts sobek.Value) (*sobek.Promise, error) {
popts := common.NewBrowserContextOptions()
if err := popts.Parse(vu.Context(), opts); err != nil {
popts, err := parseBrowserContextOptions(vu.Runtime(), opts)
if err != nil {
return nil, fmt.Errorf("parsing browser.newContext options: %w", err)
}
return k6ext.Promise(vu.Context(), func() (any, error) {
Expand Down Expand Up @@ -71,8 +71,8 @@ func mapBrowser(vu moduleVU) mapping { //nolint:funlen,cyclop,gocognit
return b.Version(), nil
},
"newPage": func(opts sobek.Value) (*sobek.Promise, error) {
popts := common.NewBrowserContextOptions()
if err := popts.Parse(vu.Context(), opts); err != nil {
popts, err := parseBrowserContextOptions(vu.Runtime(), opts)
if err != nil {
return nil, fmt.Errorf("parsing browser.newPage options: %w", err)
}
return k6ext.Promise(vu.Context(), func() (any, error) {
Expand Down Expand Up @@ -107,3 +107,12 @@ func initBrowserContext(bctx *common.BrowserContext, testRunID string) error {

return nil
}

// parseBrowserContextOptions parses the [common.BrowserContext] options from a Sobek value.
func parseBrowserContextOptions(rt *sobek.Runtime, opts sobek.Value) (*common.BrowserContextOptions, error) {
b := common.DefaultBrowserContextOptions()
if err := mergeWith(rt, b, opts); err != nil {
return nil, err
}
return b, nil
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package browser

import (
"github.com/grafana/xk6-browser/common"
"go.k6.io/k6/js/modules/k6/browser/common"
)

// mapConsoleMessage to the JS module.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (

"github.com/grafana/sobek"

"github.com/grafana/xk6-browser/common"
"github.com/grafana/xk6-browser/k6ext"
"go.k6.io/k6/js/modules/k6/browser/common"
"go.k6.io/k6/js/modules/k6/browser/k6ext"
)

// mapElementHandle to the JS module.
Expand Down
Loading
Loading