@@ -2,6 +2,7 @@ package browser
2
2
3
3
import (
4
4
"fmt"
5
+ "reflect"
5
6
6
7
"github.com/grafana/sobek"
7
8
@@ -422,6 +423,31 @@ func mapFrame(vu moduleVU, f *common.Frame) mapping {
422
423
return nil , nil
423
424
})
424
425
},
426
+ "waitForURL" : func (url sobek.Value , opts sobek.Value ) (* sobek.Promise , error ) {
427
+ popts := common .NewFrameWaitForURLOptions (f .Timeout ())
428
+ if err := popts .Parse (vu .Context (), opts ); err != nil {
429
+ return nil , fmt .Errorf ("parsing waitForURL options: %w" , err )
430
+ }
431
+
432
+ var val string
433
+ switch url .ExportType () {
434
+ case reflect .TypeOf (string ("" )):
435
+ val = fmt .Sprintf ("'%s'" , url .String ()) // Strings require quotes
436
+ default : // JS Regex, CSS, numbers or booleans
437
+ val = url .String () // No quotes
438
+ }
439
+
440
+ // Inject JS regex checker for URL pattern matching
441
+ ctx := vu .Context ()
442
+ jsRegexChecker , err := injectRegexMatcherScript (ctx , vu , f .Page ().TargetID ())
443
+ if err != nil {
444
+ return nil , err
445
+ }
446
+
447
+ return k6ext .Promise (ctx , func () (result any , reason error ) {
448
+ return nil , f .WaitForURL (val , popts , jsRegexChecker )
449
+ }), nil
450
+ },
425
451
}
426
452
maps ["$" ] = func (selector string ) * sobek.Promise {
427
453
return k6ext .Promise (vu .Context (), func () (any , error ) {
0 commit comments