grafana/k6 · error

%s network cache: %w

Error message

%s network cache: %w

What it means

The CDP command Network.SetCacheDisabled failed while the browser module was enabling or disabling the page's network cache. The message prefix says which direction ('enabling'/'disabling' cache). It surfaces through SetCacheEnabled via k6ext.Panicf, so it aborts the current iteration.

Source

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

	e, ok := m.reqIDToRequestPausedEvent[reqID]

	return e, ok
}

func (m *NetworkManager) setRequestInterception(value bool) error {
	m.userReqInterceptionEnabled = value
	return m.updateProtocolRequestInterception()
}

func (m *NetworkManager) updateProtocolCacheDisabled() error {
	action := network.SetCacheDisabled(m.userCacheDisabled)
	if err := action.Do(cdp.WithExecutor(m.ctx, m.session)); err != nil {
		errAction := "enabling"
		if m.userCacheDisabled {
			errAction = "disabling"
		}
		return fmt.Errorf("%s network cache: %w", errAction, err)
	}
	return nil
}

func (m *NetworkManager) updateProtocolRequestInterception() error {
	enabled := m.userReqInterceptionEnabled
	if enabled == m.protocolReqInterceptionEnabled {
		return nil
	}

	m.protocolReqInterceptionEnabled = enabled
	m.logger.Debugf("NetworkManager:updateProtocolRequestInterception",
		"updating request interception to %t (session: %s)", enabled, m.session.ID())

	actions := []Action{
		network.SetCacheDisabled(true),
		fetch.Enable().
			WithHandleAuthRequests(true).

View on GitHub (pinned to 93accf6570)

Solutions

  1. Reorder the script so cache toggles happen right after page creation, before any close/teardown can race it
  2. Check whether the browser crashed (inspect k6 debug logs, DEBUG=k6-browser); fix memory/timeout issues if so
  3. Ensure the browser binary matches the version k6 bundles/downloads (don't mix an old chrome with a newer k6)
  4. Wrap the call site so teardown races are avoided: stop issuing CDP-touching calls after page.close()

Example fix

// before
page.on('request', () => page.setCacheEnabled(false)); // may race close

// after
await page.setCacheEnabled(false); // once, right after page creation
await page.goto('https://test.k6.io/');
Defensive patterns

Strategy: try-catch

Validate before calling

if (page.isClosed()) { throw new Error('cannot set cache: page is closed'); }
await page.setCacheEnabled(false);

Try / catch

try {
  await page.setCacheEnabled(false);
} catch (e) {
  // Session-level CDP failure; safe to skip if iteration is ending
  if (!/network cache/.test(String(e))) throw e;
  console.warn('cache toggle failed:', e.message);
}

Prevention

When it happens

Trigger: Calling page.setCacheEnabled(true/false) or browserContext page creation with cache settings (userCacheDisabled flips at network_manager.go:1098) after the page's CDP session is already closed, the browser process has crashed, or the DevTools connection is broken. Also seen when the browser is being torn down at the end of an iteration while the handler is still running.

Common situations: Calling setCacheEnabled inside a page.on('request') handler that races page/context close; headless Chrome killed by the OS (OOM) mid-test; running with an incompatible or older chromium binary whose CDP target dropped the session.

Related errors


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