{"record":{"id":"cf4762e3c9c16684","repo":"grafana/k6","slug":"updating-extra-http-headers-w","errorCode":null,"errorMessage":"updating extra HTTP headers: %w","messagePattern":"updating extra HTTP headers: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame_session.go","lineNumber":1152,"sourceCode":"\t\treturn fmt.Errorf(\"internal error while updating emulated media: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc (fs *FrameSession) updateExtraHTTPHeaders(initial bool) error {\n\tfs.logger.Debugf(\"NewFrameSession:updateExtraHTTPHeaders\", \"sid:%v tid:%v\", fs.session.ID(), fs.targetID)\n\n\t// Merge extra headers from browser context and page, where page specific headers ake precedence.\n\tmergedHeaders := make(network.Headers)\n\tfor k, v := range fs.page.browserCtx.opts.ExtraHTTPHeaders {\n\t\tmergedHeaders[k] = v\n\t}\n\tfor k, v := range fs.page.extraHTTPHeaders {\n\t\tmergedHeaders[k] = v\n\t}\n\tif !initial || len(mergedHeaders) > 0 {\n\t\tif err := fs.networkManager.SetExtraHTTPHeaders(mergedHeaders); err != nil {\n\t\t\treturn fmt.Errorf(\"updating extra HTTP headers: %w\", err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (fs *FrameSession) updateGeolocation(initial bool) error {\n\tfs.logger.Debugf(\"NewFrameSession:updateGeolocation\", \"sid:%v tid:%v\", fs.session.ID(), fs.targetID)\n\n\tgeolocation := fs.page.browserCtx.opts.Geolocation\n\tif !initial || geolocation != nil {\n\t\taction := emulation.SetGeolocationOverride().\n\t\t\tWithLatitude(geolocation.Latitude).\n\t\t\tWithLongitude(geolocation.Longitude).\n\t\t\tWithAccuracy(geolocation.Accuracy)\n\t\tif err := action.Do(cdp.WithExecutor(fs.ctx, fs.session)); err != nil {\n\t\t\treturn fmt.Errorf(\"%w\", err)\n\t\t}","sourceCodeStart":1134,"sourceCodeEnd":1170,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/frame_session.go#L1134-L1170","documentation":"Extra HTTP headers configured on the browser context (extraHTTPHeaders option) or set on a page are merged (page headers win) and pushed to the browser through the network manager via Network.setExtraHTTPHeaders. This error means that underlying call failed while applying the merged header map.","triggerScenarios":"Creating a context/page with extraHTTPHeaders, or calling page.setExtraHTTPHeaders(), when the frame's network session is unavailable: page closing or closed, browser disconnected, or a header map the browser rejects (for example non-string values marshalled to objects/arrays).","commonSituations":"Injecting auth, tenant or trace headers into every request; passing numbers/objects as header values from the k6 script; applying headers during initial page setup racing with target attachment; browser crash under load.","solutions":["Make every header value a plain string (String(value)) before passing it","Apply extraHTTPHeaders at context/page creation time rather than after navigation, and guard page-level calls with page.isClosed()","Retry once if the failure coincided with setup or navigation","If persistent, look for accompanying CDP errors indicating the browser process died"],"exampleFix":"// before\nconst ctx = await browser.newContext({ extraHTTPHeaders: { 'X-Count': 42 } });\n\n// after\nconst ctx = await browser.newContext({ extraHTTPHeaders: { 'X-Count': '42' } });","handlingStrategy":"validation","validationCode":"const headers = { 'X-Tenant': 'acme', 'X-Count': String(42) };\nfor (const [k, v] of Object.entries(headers)) {\n  if (typeof v !== 'string') throw new Error(`header ${k} must be a string`);\n}\nawait page.setExtraHTTPHeaders(headers);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass string header values","Prefer context-level extraHTTPHeaders at creation over per-page updates","Do not change headers while the page is closing or mid-navigation"],"tags":["browser","http-headers","network","cdp","configuration"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}