{"record":{"id":"ccc7c679d62f1349","repo":"grafana/k6","slug":"internal-error-while-updating-protocol-request-int","errorCode":null,"errorMessage":"internal error while updating protocol request interception %T: %w","messagePattern":"internal error while updating protocol request interception %T: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/network_manager.go","lineNumber":889,"sourceCode":"\t\tnetwork.SetCacheDisabled(true),\n\t\tfetch.Enable().\n\t\t\tWithHandleAuthRequests(true).\n\t\t\tWithPatterns([]*fetch.RequestPattern{\n\t\t\t\t{\n\t\t\t\t\tURLPattern:   \"*\",\n\t\t\t\t\tRequestStage: fetch.RequestStageRequest,\n\t\t\t\t},\n\t\t\t}),\n\t}\n\tif !enabled {\n\t\tactions = []Action{\n\t\t\tnetwork.SetCacheDisabled(false),\n\t\t\tfetch.Disable(),\n\t\t}\n\t}\n\tfor _, action := range actions {\n\t\tif err := action.Do(cdp.WithExecutor(m.ctx, m.session)); err != nil {\n\t\t\treturn fmt.Errorf(\"internal error while updating protocol request interception %T: %w\", action, err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// Authenticate sets HTTP authentication credentials to use.\nfunc (m *NetworkManager) Authenticate(credentials Credentials) error {\n\tm.credentials = credentials\n\tif !credentials.IsEmpty() {\n\t\tm.userReqInterceptionEnabled = true\n\t}\n\tif err := m.updateProtocolRequestInterception(); err != nil {\n\t\treturn fmt.Errorf(\"setting authentication credentials: %w\", err)\n\t}\n\n\treturn nil\n}","sourceCodeStart":871,"sourceCodeEnd":907,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/network_manager.go#L871-L907","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Confirm the page is still open (page.isClosed() === false) before route()/unroute()","Move route() registration to immediately after page creation instead of inside event handlers or late in the script","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","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"],"exampleFix":"// before\nsetTimeout(() => page.route('**/*', r => r.continue()), 5000); // races page close\n\n// after\nawait page.route('**/*', r => r.continue()); // registered while page is live\nawait page.goto('https://test.k6.io/');","handlingStrategy":"try-catch","validationCode":"if (page.isClosed()) { /* skip route registration */ }\nawait page.route('**/*', handler);","typeGuard":null,"tryCatchPattern":"try {\n  await page.route('**/*', h => h.continue());\n} catch (e) {\n  if (/updating protocol request interception/.test(String(e))) {\n    console.warn('interception unavailable; browser session likely closed');\n    return; // degrade gracefully: run without interception\n  }\n  throw e;\n}","preventionTips":["Register route()/unroute() while the page is guaranteed open (immediately after newPage)","Always unroute before close to keep Fetch enable/disable ordering clean","If this fires at iteration end, restructure so interception changes finish before teardown"],"tags":["cdp","browser","request-interception","route","lifecycle"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}