grafana/k6 · error

creating url matcher for path

Error message

creating url matcher for path %s: %w

What it means

Failure to build the URL matcher while registering a page route: the glob/regex path combined with the RegExMatcher could not be compiled into a pattern matcher. The offending input is the path string passed to page.route().

Solutions

  1. Provide a valid glob (e.g. '**/api/**') or a syntactically correct regex for the route path
  2. Escape regex metacharacters when matching literal URLs
  3. Test route patterns against the URLs your test actually requests
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/js/modules/k6/browser/common/page.go:1370 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@3fcf5388d7 (2026-08-18). Data as JSON: /api/errors/dc2af14a1fc53296. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/common/page.go:1375

	return nm.extraHTTPHeaders["referer"]
}

// Route registers a handler to be executed for a given request path
func (p *Page) Route(path string, cb RouteHandlerCallback, rm RegExMatcher) error {
	p.logger.Debugf("Page:Route", "sid:%v path:%s", p.sessionID(), path)

	p.routesMu.Lock()
	defer p.routesMu.Unlock()
	if len(p.routes) == 0 {
		err := p.mainFrameSession.updateRequestInterception(true)
		if err != nil {
			return err
		}
	}

	matcher, err := newPatternMatcher(path, rm)
	if err != nil {
		return fmt.Errorf("creating url matcher for path %s: %w", path, err)
	}

	routeHandler := NewRouteHandler(path, cb, matcher)
	// Append new route at the beginning of the slice as, when several routes match the given pattern,
	// they will run in the opposite order to their registration.
	p.routes = append([]*RouteHandler{routeHandler}, p.routes...)

	return nil
}

// Unroute removes the route(s) for the specified URL pattern.
// If multiple routes match the same URL pattern, all of them are removed.
func (p *Page) Unroute(path string) error {
	p.logger.Debugf("Page:Unroute", "sid:%v path:%s", p.sessionID(), path)

	p.routesMu.Lock()
	defer p.routesMu.Unlock()

View on GitHub (pinned to 3fcf5388d7)