grafana/k6 · error

internal error while updating protocol request interception

Error message

internal error while updating protocol request interception %T: %w

What it means

While switching the Fetch domain on or off for request interception, one of the CDP actions (Fetch.enable/Fetch.disable or the paired Network.SetCacheDisabled) failed. 'internal error' signals an infrastructure-level CDP failure, not a script logic problem: the page's session could not execute the command.

Source

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

		network.SetCacheDisabled(true),
		fetch.Enable().
			WithHandleAuthRequests(true).
			WithPatterns([]*fetch.RequestPattern{
				{
					URLPattern:   "*",
					RequestStage: fetch.RequestStageRequest,
				},
			}),
	}
	if !enabled {
		actions = []Action{
			network.SetCacheDisabled(false),
			fetch.Disable(),
		}
	}
	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
}

View on GitHub (pinned to 93accf6570)

Solutions

  1. Confirm the page is still open (page.isClosed() === false) before route()/unroute()
  2. Move route() registration to immediately after page creation instead of inside event handlers or late in the script
  3. Check k6-browser debug logs (DEBUG=k6-browser) for an earlier session/browser failure — this error is usually a symptom, so fix the root crash/disconnect
  4. If it happens only at iteration end, it is teardown noise: avoid issuing route changes once the iteration is ending, or increase timeBetweenIteration if handlers race close

Example fix

// before
setTimeout(() => page.route('**/*', r => r.continue()), 5000); // races page close

// after
await page.route('**/*', r => r.continue()); // registered while page is live
await page.goto('https://test.k6.io/');
Defensive patterns

Strategy: try-catch

Validate before calling

if (page.isClosed()) { /* skip route registration */ }
await page.route('**/*', handler);

Try / catch

try {
  await page.route('**/*', h => h.continue());
} catch (e) {
  if (/updating protocol request interception/.test(String(e))) {
    console.warn('interception unavailable; browser session likely closed');
    return; // degrade gracefully: run without interception
  }
  throw e;
}

Prevention

When it happens

Trigger: First page.route()/unroute() on a page (which flips userReqInterceptionEnabled and calls updateProtocolRequestInterception), or Authenticate() with credentials enabling interception, executed when the target/session is destroyed, the tab was closed, or the browser process died. Also occurs when route() is registered during iteration teardown.

Common situations: Registering routes on a page whose navigation already destroyed the target; the site opening/closing popup targets rapidly; chromium crashing under memory pressure during long browser tests; calling route() inside a handler that runs after page.close() started.

Related errors


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