{"record":{"id":"38b6d7d18e508171","repo":"grafana/k6","slug":"s-network-cache-w","errorCode":null,"errorMessage":"%s network cache: %w","messagePattern":"(.+?) network cache: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/network_manager.go","lineNumber":855,"sourceCode":"\n\te, ok := m.reqIDToRequestPausedEvent[reqID]\n\n\treturn e, ok\n}\n\nfunc (m *NetworkManager) setRequestInterception(value bool) error {\n\tm.userReqInterceptionEnabled = value\n\treturn m.updateProtocolRequestInterception()\n}\n\nfunc (m *NetworkManager) updateProtocolCacheDisabled() error {\n\taction := network.SetCacheDisabled(m.userCacheDisabled)\n\tif err := action.Do(cdp.WithExecutor(m.ctx, m.session)); err != nil {\n\t\terrAction := \"enabling\"\n\t\tif m.userCacheDisabled {\n\t\t\terrAction = \"disabling\"\n\t\t}\n\t\treturn fmt.Errorf(\"%s network cache: %w\", errAction, err)\n\t}\n\treturn nil\n}\n\nfunc (m *NetworkManager) updateProtocolRequestInterception() error {\n\tenabled := m.userReqInterceptionEnabled\n\tif enabled == m.protocolReqInterceptionEnabled {\n\t\treturn nil\n\t}\n\n\tm.protocolReqInterceptionEnabled = enabled\n\tm.logger.Debugf(\"NetworkManager:updateProtocolRequestInterception\",\n\t\t\"updating request interception to %t (session: %s)\", enabled, m.session.ID())\n\n\tactions := []Action{\n\t\tnetwork.SetCacheDisabled(true),\n\t\tfetch.Enable().\n\t\t\tWithHandleAuthRequests(true).","sourceCodeStart":837,"sourceCodeEnd":873,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/network_manager.go#L837-L873","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Reorder the script so cache toggles happen right after page creation, before any close/teardown can race it","Check whether the browser crashed (inspect k6 debug logs, DEBUG=k6-browser); fix memory/timeout issues if so","Ensure the browser binary matches the version k6 bundles/downloads (don't mix an old chrome with a newer k6)","Wrap the call site so teardown races are avoided: stop issuing CDP-touching calls after page.close()"],"exampleFix":"// before\npage.on('request', () => page.setCacheEnabled(false)); // may race close\n\n// after\nawait page.setCacheEnabled(false); // once, right after page creation\nawait page.goto('https://test.k6.io/');","handlingStrategy":"try-catch","validationCode":"if (page.isClosed()) { throw new Error('cannot set cache: page is closed'); }\nawait page.setCacheEnabled(false);","typeGuard":null,"tryCatchPattern":"try {\n  await page.setCacheEnabled(false);\n} catch (e) {\n  // Session-level CDP failure; safe to skip if iteration is ending\n  if (!/network cache/.test(String(e))) throw e;\n  console.warn('cache toggle failed:', e.message);\n}","preventionTips":["Toggle cache once, right after page creation, never inside event handlers or after close()","Treat any cache-toggle failure as a signal to check browser health (earlier crash) before continuing","Avoid cache toggles at iteration boundaries; they race teardown"],"tags":["cdp","browser","cache","network","lifecycle"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}