{"record":{"id":"99414b07902731b5","repo":"grafana/k6","slug":"setting-authentication-credentials-w","errorCode":null,"errorMessage":"setting authentication credentials: %w","messagePattern":"setting authentication credentials: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/network_manager.go","lineNumber":903,"sourceCode":"\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}\n\nfunc (m *NetworkManager) AbortRequest(requestID fetch.RequestID, errorReason string) error {\n\tm.logger.Debugf(\"NetworkManager:AbortRequest\", \"aborting request (id: %s, errorReason: %s)\",\n\t\trequestID, errorReason)\n\tnetErrorReason, ok := m.errorReasons[errorReason]\n\tif !ok {\n\t\treturn fmt.Errorf(\"unknown error code: %s\", errorReason)\n\t}\n\n\taction := fetch.FailRequest(requestID, netErrorReason)\n\tif err := action.Do(cdp.WithExecutor(m.ctx, m.session)); err != nil {\n\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.","sourceCodeStart":885,"sourceCodeEnd":921,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/network_manager.go#L885-L921","documentation":"NetworkManager.Authenticate stored HTTP credentials and enabled request interception to answer auth challenges, but the underlying protocol update (Fetch.enable etc.) failed. This is the same internal interception failure as error 942, wrapped with the credentials context.","triggerScenarios":"Creating a browser context with httpCredentials: {username, password} (or calling the auth API) and enabling interception on a page whose CDP session is closed or whose browser/target has gone away, e.g. credentials applied after page close or during browser shutdown.","commonSituations":"browser.newContext({httpCredentials: {...}}) for basic-auth sites while chromium is unstable or already closing; mixing context creation with rapid page churn (redirects/popups destroying targets); long soak tests where the browser crashed earlier and this is the first call to notice.","solutions":["Verify the browser/context/page are still alive before relying on httpCredentials (check earlier errors in the log — this is typically downstream of a browser crash)","Restart-friendly pattern: keep context creation early in the iteration and complete all auth-dependent work before closing pages","If it recurs, capture DEBUG=k6-browser output to find the first CDP failure (this message only wraps it)","Upgrade k6 — the browser module and its bundled chromium evolve together; version skew can cause CDP command rejections"],"exampleFix":"// before\nconst ctx = browser.newContext();\nawait page.close();\nctx.setHTTPCredentials ? null : null; // late auth setup on dead targets\n\n// after\nconst ctx = browser.newContext({ httpCredentials: { username: 'u', password: 'p' } });\nconst page = await ctx.newPage();\nawait page.goto('https://test.k6.io/');","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const ctx = browser.newContext({ httpCredentials: { username: 'u', password: 'p' } });\n} catch (e) {\n  if (/setting authentication credentials/.test(String(e))) {\n    throw new Error('browser unusable (crashed/closed); restart iteration');\n  }\n  throw e;\n}","preventionTips":["Set httpCredentials at context creation, not later on a used page","Watch for the first browser error in logs — this message is downstream of a session-level failure","Keep auth setup early in the iteration, away from close() races"],"tags":["cdp","browser","authentication","request-interception","lifecycle"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}