{"record":{"id":"1ef63af19aebaa81","repo":"grafana/k6","slug":"parsing-url-pattern-w","errorCode":null,"errorMessage":"parsing URL pattern: %w","messagePattern":"parsing URL pattern: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame.go","lineNumber":2085,"sourceCode":"}\n\n// WaitForNavigation waits for the given navigation lifecycle event to happen.\n// RegExMatcher should be non-nil to be able to test against a URL pattern in the options.\n//\n//nolint:funlen\nfunc (f *Frame) WaitForNavigation(opts *FrameWaitForNavigationOptions, rm RegExMatcher) (*Response, error) {\n\tf.log.Debugf(\"Frame:WaitForNavigation\",\n\t\t\"fid:%s furl:%s url:%s\", f.ID(), f.URL(), opts.URL)\n\tdefer f.log.Debugf(\"Frame:WaitForNavigation:return\",\n\t\t\"fid:%s furl:%s\", f.ID(), f.URL())\n\n\ttimeoutCtx, timeoutCancel := context.WithTimeout(f.ctx, opts.Timeout)\n\n\t// Create URL matcher based on the pattern\n\tmatcher, err := newPatternMatcher(opts.URL, rm)\n\tif err != nil {\n\t\ttimeoutCancel()\n\t\treturn nil, fmt.Errorf(\"parsing URL pattern: %w\", err)\n\t}\n\n\tvar matcherErr error\n\tnavEvtCh, navEvtCancel := createWaitForEventPredicateHandler(timeoutCtx, f, []string{EventFrameNavigation},\n\t\tfunc(data any) bool {\n\t\t\tif navEvt, ok := data.(*NavigationEvent); ok {\n\t\t\t\t// Check if the navigation URL matches the pattern\n\t\t\t\tmatched, err := matcher(navEvt.url)\n\t\t\t\tif err != nil {\n\t\t\t\t\tmatcherErr = err\n\t\t\t\t\t// Return true here even though it's not correct and no match\n\t\t\t\t\t// was found. We need this to exit asap so that the error can be\n\t\t\t\t\t// propagated to the caller.\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t\treturn matched\n\t\t\t}\n\t\t\treturn false","sourceCodeStart":2067,"sourceCodeEnd":2103,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/frame.go#L2067-L2103","documentation":"Thrown by Frame.WaitForNavigation when newPatternMatcher cannot build a URL matcher from opts.URL. The pattern is compiled (glob-to-regex or regex via the injected RegExMatcher) before any navigation is awaited, so a syntactically invalid pattern fails immediately with this wrap. No waiting occurs; the error is pure input validation.","triggerScenarios":"page.waitForNavigation({ url: '(unclosed' }) or any malformed regex; a glob containing characters that break the generated regex; passing a full URL where a pattern with regex metacharacters (dots, question marks) is interpreted as regex.","commonSituations":"Treating the url option as a plain string match (it is a pattern); unescaped query strings like '/search?q=1' where '?' is regex syntax; porting selectors between glob and regex dialects.","solutions":["Test the pattern in a regex tester first; remember '*' glob segments are translated but raw regex metacharacters are not escaped","Use a simple glob like '**/path/**' for substring-style matches instead of hand-written regex","Escape literal dots/question marks: '/search\\?q=1'"],"exampleFix":"// before\npage.waitForNavigation({ url: 'https://example.com/search?q=1' }); // '?' is regex\n\n// after\npage.waitForNavigation({ url: /https:\\/\\/example\\.com\\/search\\?q=1/ });\n// or glob form\npage.waitForNavigation({ url: '**/search**' });","handlingStrategy":"validation","validationCode":"function assertPattern(p) {\n  new RegExp(p.replace(/\\*\\*/g, '.*').replace(/\\*/g, '[^/]*'));\n}\nassertPattern(cfg.urlPattern); // throws early on malformed patterns","typeGuard":"function isPatternError(e) {\n  return e instanceof Error && /parsing URL pattern/.test(e.message);\n}","tryCatchPattern":null,"preventionTips":["Compile/test navigation patterns once at startup","Escape literal '?' and '.' from copied URLs"],"tags":["browser","wait-for-navigation","regex","validation"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}