{"record":{"id":"dc2af14a1fc53296","repo":"grafana/k6","slug":"creating-url-matcher-for-path-s-w","errorCode":null,"errorMessage":"creating url matcher for path %s: %w","messagePattern":"creating url matcher for path (.+?): %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/page.go","lineNumber":1370,"sourceCode":"\treturn nm.extraHTTPHeaders[\"referer\"]\n}\n\n// Route registers a handler to be executed for a given request path\nfunc (p *Page) Route(path string, cb RouteHandlerCallback, rm RegExMatcher) error {\n\tp.logger.Debugf(\"Page:Route\", \"sid:%v path:%s\", p.sessionID(), path)\n\n\tp.routesMu.Lock()\n\tdefer p.routesMu.Unlock()\n\tif len(p.routes) == 0 {\n\t\terr := p.mainFrameSession.updateRequestInterception(true)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\tmatcher, err := newPatternMatcher(path, rm)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"creating url matcher for path %s: %w\", path, err)\n\t}\n\n\trouteHandler := NewRouteHandler(path, cb, matcher)\n\t// Append new route at the beginning of the slice as, when several routes match the given pattern,\n\t// they will run in the opposite order to their registration.\n\tp.routes = append([]*RouteHandler{routeHandler}, p.routes...)\n\n\treturn nil\n}\n\n// Unroute removes the route(s) for the specified URL pattern.\n// If multiple routes match the same URL pattern, all of them are removed.\nfunc (p *Page) Unroute(path string) error {\n\tp.logger.Debugf(\"Page:Unroute\", \"sid:%v path:%s\", p.sessionID(), path)\n\n\tp.routesMu.Lock()\n\tdefer p.routesMu.Unlock()\n","sourceCodeStart":1352,"sourceCodeEnd":1388,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/page.go#L1352-L1388","documentation":"Page.Route builds a URL matcher via newPatternMatcher, which only fails at creation when a non-quoted (regex) pattern is supplied but no regex matcher function is available ('regex matcher must be provided'). In normal k6 operation the Sobek-based matcher is always provided, so this creation error indicates an internal misconfiguration; regex compile/match problems surface later, at request-matching time, not here.","triggerScenarios":"Calling page.route(pattern, handler) with a regex-style pattern in a code path where the browser's regex matcher was not wired in (internal/API misuse), rather than via the normal k6 script surface.","commonSituations":"Essentially unseen by JS script authors; appears only in programs embedding the browser module or after internal refactors broke matcher injection.","solutions":["If using the public page.route API, upgrade k6 — this indicates an internal wiring bug, not a script problem","Prefer quoted exact URLs ('https://host/path') or simple glob patterns, which never need the regex matcher","Report the issue with the pattern and k6 version if reproducible on the current release"],"exampleFix":"// before\nawait page.route(/api\\/v1\\//, handler); // regex path, matcher-dependent\n\n// after\nawait page.route('**/api/v1/**', handler);","handlingStrategy":"try-catch","validationCode":"if (typeof pattern !== 'string' || pattern.length === 0) throw new Error('route pattern must be a non-empty string');","typeGuard":null,"tryCatchPattern":"try {\n  await page.route(pattern, handler);\n} catch (e) {\n  if (/creating url matcher/.test(e.message)) { await page.route('**/' + pattern + '/**', handler); }\n  else throw e;\n}","preventionTips":["Prefer glob patterns ('**/api/**') or quoted exact URLs over regex strings","If this fires on the public API, report a k6 bug — matcher wiring should never be nil"],"tags":["browser","routing","request-interception","internal-error"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}