grafana/k6 · error

navigating to %q: %w

Error message

navigating to %q: %w

What it means

Thrown by FrameManager.NavigateFrame when the CDP Page.navigate command itself fails (fs.navigateFrame error) — the browser rejected or errored the navigation before any waiting began. Distinct from a timeout: this is the navigate call returning an error or an error net result, e.g. ERR_NAME_NOT_RESOLVED, ERR_ABORTED (another navigation superseded it), or a crashed target.

Source

Thrown at internal/js/modules/k6/browser/common/frame_manager.go:695

	defer lifecycleEvtCancel()

	fs, ok := frame.page.getFrameSession(cdp.FrameID(frame.ID()))
	if !ok {
		m.logger.Debugf("FrameManager:NavigateFrame",
			"fmid:%d fid:%v furl:%s url:%s fs:nil",
			fmid, fid, furl, url)

		// Attaching an iframe to an existing page doesn't seem to trigger a "Target.attachedToTarget" event
		// from the browser even when "Target.setAutoAttach" is true. If this is the case fallback to the

		// main frame's session.
		fs = frame.page.mainFrameSession
	}

	var err error
	newDocumentID, err = fs.navigateFrame(frame, url, parsedOpts.Referer)
	if err != nil {
		return nil, fmt.Errorf("navigating to %q: %w", url, err)
	}

	if newDocumentID == "" {
		// It's a navigation within the same document (e.g., via anchor links or
		// the History API), so don't wait for a response nor any lifecycle
		// events.
		return nil, nil //nolint:nilnil
	}

	// unblock the waiter goroutine
	close(newDocIDIsReadyCh)

	wrapTimeoutError := func(err error) error {
		if errors.Is(err, context.DeadlineExceeded) {
			err = &k6ext.UserFriendlyError{
				Err:     err,
				Timeout: parsedOpts.Timeout,
			}

View on GitHub (pinned to 93accf6570)

Solutions

  1. Always pass a fully-qualified URL with scheme: page.goto('http://localhost:3000/')
  2. Verify reachability from where k6 runs: curl the same URL from that container/host
  3. Ensure the local dev server is up before the test (k6 browser tests need a live target)
  4. Avoid issuing a second goto while the first is in flight

Example fix

// before
page.goto('localhost:3000/app');

// after
page.goto('http://localhost:3000/app');
Defensive patterns

Strategy: validation

Validate before calling

function assertGotoURL(u) {
  const parsed = new URL(u);
  if (!/^https?:$/.test(parsed.protocol)) throw new Error(`use http(s) URL, got ${u}`);
}
assertGotoURL(targetUrl);

Type guard

function isNavigateRejected(e) {
  return e instanceof Error && /navigating to .*:/.test(e.message) && /ERR_/.test(e.message);
}

Prevention

When it happens

Trigger: page.goto('localhost:3000') without a scheme (parsed as relative and rejected); DNS failure in the test container; net::ERR_CONNECTION_REFUSED because the local server is not up; a download or redirect chain interrupting navigation (ERR_ABORTED); browser process crashed.

Common situations: Forgetting http:// in local URLs; k6 running in a container or CI that cannot resolve/reach the target host; the app under test restarting mid-test; concurrent navigations to the same page.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/5c618862245bc9e2. Report an issue: GitHub.