grafana/k6 · error
waiting for URL %q: %w
Error message
waiting for URL %q: %w
What it means
Thrown by Frame.WaitForURL when the RegExMatcher fails while testing urlPattern against the current frame URL — i.e. the pattern itself cannot be compiled, before any waiting logic matters. Identical failure class to the waitForNavigation pattern error, but surfaced from the fast-path check that decides whether the frame is already at the target URL.
Source
Thrown at internal/js/modules/k6/browser/common/frame.go:2224
f.log.Debugf("Frame:WaitForTimeout", "fid:%s furl:%q timeout:%s", f.ID(), f.URL(), to)
defer f.log.Debugf("Frame:WaitForTimeout:return", "fid:%s furl:%q timeout:%s", f.ID(), f.URL(), to)
select {
case <-f.ctx.Done():
case <-time.After(to):
}
}
// WaitForURL waits for the frame to navigate to a URL matching the given pattern.
// RegExMatcher should be non-nil to be able to test against a URL pattern.
func (f *Frame) WaitForURL(urlPattern string, opts *FrameWaitForURLOptions, rm RegExMatcher) error {
f.log.Debugf("Frame:WaitForURL", "fid:%s furl:%q pattern:%s", f.ID(), f.URL(), urlPattern)
defer f.log.Debugf("Frame:WaitForURL:return", "fid:%s furl:%q pattern:%s", f.ID(), f.URL(), urlPattern)
matched, err := rm.Match(urlPattern, f.URL())
if err != nil {
return fmt.Errorf("waiting for URL %q: %w", urlPattern, err)
}
if matched {
// Already at target URL, just wait for load state
return f.WaitForLoadState(opts.WaitUntil.String(), &FrameWaitForLoadStateOptions{
Timeout: opts.Timeout,
})
}
// Wait for navigation to matching URL
navOpts := &FrameWaitForNavigationOptions{
URL: urlPattern,
Timeout: opts.Timeout,
WaitUntil: opts.WaitUntil,
}
_, err = f.WaitForNavigation(navOpts, rm)
return err
}View on GitHub (pinned to 93accf6570)
Solutions
- Escape regex metacharacters or use a dedicated RegExp literal: page.waitForURL(/\/orders\/\d+$/)
- For substring matching use a pattern like '**/orders/**' if glob semantics are enabled, otherwise anchor a simple regex
Example fix
// before
page.waitForURL('https://example.com/checkout?step=2');
// after
page.waitForURL(/https:\/\/example\.com\/checkout\?step=2/); Defensive patterns
Strategy: validation
Validate before calling
function assertURLPattern(p) {
if (typeof p === 'string') new RegExp(p); // throws on malformed regex
}
assertURLPattern(pattern); Type guard
function isWaitForURLPatternError(e) {
return e instanceof Error && /waiting for URL/.test(e.message);
} Prevention
- Use RegExp literals with escaped metacharacters
- Validate all URL patterns once at suite start
When it happens
Trigger: page.waitForURL('(bad[') or a string pattern containing unescaped regex metacharacters ('?' of a query string, '.'); the very first Match call fails, so the error appears immediately, even if the page is already on the target URL.
Common situations: Passing a full URL with query strings as a plain string; mixing glob syntax where regex is expected; patterns copied from other tools with different dialects.
Related errors
- parsing URL pattern: %w
- matching %q against pattern %q: %w
- predicate function is not callable
- "handler" argument cannot be nil
- clip area is either empty or outside the viewport
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/78d4a4b394c919af.
Report an issue: GitHub.