{"record":{"id":"73e95ac40402dd86","repo":"grafana/k6","slug":"fail-to-continue-request-id-s-w","errorCode":null,"errorMessage":"fail to continue request (id: %s): %w","messagePattern":"fail to continue request \\(id: (.+?)\\): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/network_manager.go","lineNumber":973,"sourceCode":"\t\t// Avoid logging as error when context is canceled.\n\t\t// Most probably this happens when trying to fail a site's background request\n\t\t// while the iteration is ending and therefore the browser context is being closed.\n\t\tif errors.Is(err, context.Canceled) {\n\t\t\tm.logger.Debug(\"NetworkManager:ContinueRequest\", \"context canceled continuing request\")\n\t\t\treturn nil\n\t\t}\n\n\t\t// This error message is an internal issue, rather than something that the user can\n\t\t// action on. It's also usually ok to ignore since it means that the page has navigated\n\t\t// away or something has occurred which means that the request is no longer needed and\n\t\t// isn't being tracked by chromium.\n\t\tif strings.Contains(err.Error(), \"Invalid InterceptionId\") {\n\t\t\tm.logger.Debugf(\"NetworkManager:ContinueRequest\", \"invalid interception ID (%s) continuing request: %s\",\n\t\t\t\trequestID, err)\n\t\t\treturn nil\n\t\t}\n\n\t\treturn fmt.Errorf(\"fail to continue request (id: %s): %w\", requestID, err)\n\t}\n\n\treturn nil\n}\n\nfunc (m *NetworkManager) FulfillRequest(request *Request, opts FulfillOptions) error {\n\tresponseCode := int64(http.StatusOK)\n\tif opts.Status != 0 {\n\t\tresponseCode = opts.Status\n\t}\n\n\taction := fetch.FulfillRequest(request.interceptionID, responseCode)\n\n\tif opts.ContentType != \"\" {\n\t\topts.Headers = append(opts.Headers, HTTPHeader{\n\t\t\tName:  \"Content-Type\",\n\t\t\tValue: opts.ContentType,\n\t\t})","sourceCodeStart":955,"sourceCodeEnd":991,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/network_manager.go#L955-L991","documentation":"The CDP command Fetch.continueRequest failed while resuming an intercepted request. The known-benign 'Invalid InterceptionId' case is already filtered out and logged as debug; this error means something else went wrong — the interception was never enabled for this session, the request is stale, or the session is gone.","triggerScenarios":"route.continue() after the page navigated and the interception was torn down; calling continue() twice on the same route handler; calling continue() after unroute() disabled Fetch on that target; issuing it after context close but before context cancellation propagates.","commonSituations":"Async route handlers that await slow work then continue(); handlers racing navigation/redirect; SPAs where chromium already dropped the request. Frequently appears together with rapid goto() calls in a loop.","solutions":["Call continue() exactly once, synchronously, at the top of the handler","Await route registration before goto() and unroute() before close() so Fetch is enabled/disabled in order","If the handler must do async work first, re-fetch a fresh route or accept the failure — guard the call and log it rather than failing the iteration","Enable DEBUG=k6-browser to see whether the underlying error is 'Fetch.enable isn't enabled' (ordering bug) vs session-closed (lifecycle race)"],"exampleFix":"// before\npage.route('**/api/**', async r => {\n  const data = await otherWork();\n  await r.continue(); // interception may be stale\n});\n\n// after\npage.route('**/api/**', r => r.continue()); // continue immediately","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await route.continue();\n} catch (e) {\n  const s = String(e);\n  if (/fail to continue request/.test(s)) return; // request already gone\n  throw e;\n}","preventionTips":["Continue exactly once per intercepted request, ideally synchronously","Await route registration before goto() and unroute() before close()","Keep handler logic synchronous when the decision needs no I/O; defer only when you accept staleness"],"tags":["cdp","browser","route","continue","race-condition"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}