{"record":{"id":"78d4a4b394c919af","repo":"grafana/k6","slug":"waiting-for-url-q-w","errorCode":null,"errorMessage":"waiting for URL %q: %w","messagePattern":"waiting for URL %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame.go","lineNumber":2224,"sourceCode":"\n\tf.log.Debugf(\"Frame:WaitForTimeout\", \"fid:%s furl:%q timeout:%s\", f.ID(), f.URL(), to)\n\tdefer f.log.Debugf(\"Frame:WaitForTimeout:return\", \"fid:%s furl:%q timeout:%s\", f.ID(), f.URL(), to)\n\n\tselect {\n\tcase <-f.ctx.Done():\n\tcase <-time.After(to):\n\t}\n}\n\n// WaitForURL waits for the frame to navigate to a URL matching the given pattern.\n// RegExMatcher should be non-nil to be able to test against a URL pattern.\nfunc (f *Frame) WaitForURL(urlPattern string, opts *FrameWaitForURLOptions, rm RegExMatcher) error {\n\tf.log.Debugf(\"Frame:WaitForURL\", \"fid:%s furl:%q pattern:%s\", f.ID(), f.URL(), urlPattern)\n\tdefer f.log.Debugf(\"Frame:WaitForURL:return\", \"fid:%s furl:%q pattern:%s\", f.ID(), f.URL(), urlPattern)\n\n\tmatched, err := rm.Match(urlPattern, f.URL())\n\tif err != nil {\n\t\treturn fmt.Errorf(\"waiting for URL %q: %w\", urlPattern, err)\n\t}\n\tif matched {\n\t\t// Already at target URL, just wait for load state\n\t\treturn f.WaitForLoadState(opts.WaitUntil.String(), &FrameWaitForLoadStateOptions{\n\t\t\tTimeout: opts.Timeout,\n\t\t})\n\t}\n\n\t// Wait for navigation to matching URL\n\tnavOpts := &FrameWaitForNavigationOptions{\n\t\tURL:       urlPattern,\n\t\tTimeout:   opts.Timeout,\n\t\tWaitUntil: opts.WaitUntil,\n\t}\n\t_, err = f.WaitForNavigation(navOpts, rm)\n\n\treturn err\n}","sourceCodeStart":2206,"sourceCodeEnd":2242,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/frame.go#L2206-L2242","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\npage.waitForURL('https://example.com/checkout?step=2');\n\n// after\npage.waitForURL(/https:\\/\\/example\\.com\\/checkout\\?step=2/);","handlingStrategy":"validation","validationCode":"function assertURLPattern(p) {\n  if (typeof p === 'string') new RegExp(p); // throws on malformed regex\n}\nassertURLPattern(pattern);","typeGuard":"function isWaitForURLPatternError(e) {\n  return e instanceof Error && /waiting for URL/.test(e.message);\n}","tryCatchPattern":null,"preventionTips":["Use RegExp literals with escaped metacharacters","Validate all URL patterns once at suite start"],"tags":["browser","wait-for-url","regex","validation"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}