grafana/k6 · error

setting authentication credentials: %w

Error message

setting authentication credentials: %w

What it means

NetworkManager.Authenticate stored HTTP credentials and enabled request interception to answer auth challenges, but the underlying protocol update (Fetch.enable etc.) failed. This is the same internal interception failure as error 942, wrapped with the credentials context.

Source

Thrown at internal/js/modules/k6/browser/common/network_manager.go:903

		}
	}
	for _, action := range actions {
		if err := action.Do(cdp.WithExecutor(m.ctx, m.session)); err != nil {
			return fmt.Errorf("internal error while updating protocol request interception %T: %w", action, err)
		}
	}

	return nil
}

// Authenticate sets HTTP authentication credentials to use.
func (m *NetworkManager) Authenticate(credentials Credentials) error {
	m.credentials = credentials
	if !credentials.IsEmpty() {
		m.userReqInterceptionEnabled = true
	}
	if err := m.updateProtocolRequestInterception(); err != nil {
		return fmt.Errorf("setting authentication credentials: %w", err)
	}

	return nil
}

func (m *NetworkManager) AbortRequest(requestID fetch.RequestID, errorReason string) error {
	m.logger.Debugf("NetworkManager:AbortRequest", "aborting request (id: %s, errorReason: %s)",
		requestID, errorReason)
	netErrorReason, ok := m.errorReasons[errorReason]
	if !ok {
		return fmt.Errorf("unknown error code: %s", errorReason)
	}

	action := fetch.FailRequest(requestID, netErrorReason)
	if err := action.Do(cdp.WithExecutor(m.ctx, m.session)); err != nil {
		// Avoid logging as error when context is canceled.
		// Most probably this happens when trying to fail a site's background request
		// while the iteration is ending and therefore the browser context is being closed.

View on GitHub (pinned to 93accf6570)

Solutions

  1. Verify the browser/context/page are still alive before relying on httpCredentials (check earlier errors in the log — this is typically downstream of a browser crash)
  2. Restart-friendly pattern: keep context creation early in the iteration and complete all auth-dependent work before closing pages
  3. If it recurs, capture DEBUG=k6-browser output to find the first CDP failure (this message only wraps it)
  4. Upgrade k6 — the browser module and its bundled chromium evolve together; version skew can cause CDP command rejections

Example fix

// before
const ctx = browser.newContext();
await page.close();
ctx.setHTTPCredentials ? null : null; // late auth setup on dead targets

// after
const ctx = browser.newContext({ httpCredentials: { username: 'u', password: 'p' } });
const page = await ctx.newPage();
await page.goto('https://test.k6.io/');
Defensive patterns

Strategy: try-catch

Try / catch

try {
  const ctx = browser.newContext({ httpCredentials: { username: 'u', password: 'p' } });
} catch (e) {
  if (/setting authentication credentials/.test(String(e))) {
    throw new Error('browser unusable (crashed/closed); restart iteration');
  }
  throw e;
}

Prevention

When it happens

Trigger: Creating a browser context with httpCredentials: {username, password} (or calling the auth API) and enabling interception on a page whose CDP session is closed or whose browser/target has gone away, e.g. credentials applied after page close or during browser shutdown.

Common situations: browser.newContext({httpCredentials: {...}}) for basic-auth sites while chromium is unstable or already closing; mixing context creation with rapid page churn (redirects/popups destroying targets); long soak tests where the browser crashed earlier and this is the first call to notice.

Understand the failure class

Related errors


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