{"record":{"id":"290dee407694053c","repo":"grafana/k6","slug":"throttling-network-w","errorCode":null,"errorMessage":"throttling network: %w","messagePattern":"throttling network: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/network_manager.go","lineNumber":1082,"sourceCode":"\treturn nil\n}\n\n// ThrottleNetwork changes the network attributes in chrome to simulate slower\n// networks e.g. a slow 3G connection.\nfunc (m *NetworkManager) ThrottleNetwork(networkProfile NetworkProfile) error {\n\tif m.networkProfile == networkProfile {\n\t\treturn nil\n\t}\n\tm.networkProfile = networkProfile\n\n\taction := network.EmulateNetworkConditions(\n\t\tm.offline,\n\t\tm.networkProfile.Latency,\n\t\tm.networkProfile.Download,\n\t\tm.networkProfile.Upload,\n\t)\n\tif err := action.Do(cdp.WithExecutor(m.ctx, m.session)); err != nil {\n\t\treturn fmt.Errorf(\"throttling network: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// SetUserAgent overrides the browser user agent string.\nfunc (m *NetworkManager) SetUserAgent(userAgent string) {\n\taction := emulation.SetUserAgentOverride(userAgent)\n\tif err := action.Do(cdp.WithExecutor(m.ctx, m.session)); err != nil {\n\t\tk6ext.Panicf(m.ctx, \"setting user agent: %w\", err)\n\t}\n}\n\n// SetCacheEnabled toggles cache on/off.\nfunc (m *NetworkManager) SetCacheEnabled(enabled bool) {\n\tm.userCacheDisabled = !enabled\n\tif err := m.updateProtocolCacheDisabled(); err != nil {\n\t\tk6ext.Panicf(m.ctx, \"%v\", err)","sourceCodeStart":1064,"sourceCodeEnd":1100,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/network_manager.go#L1064-L1100","documentation":"The CDP command Network.emulateNetworkConditions failed while applying a network profile (latency/download/upload) — i.e. network throttling. ThrottleNetwork short-circuits when the profile is unchanged; the error means the CDP action itself failed on the page session.","triggerScenarios":"Creating a browser context with the networkProfile option (e.g. 'Slow 3G' or a custom {latency, download, upload} profile) or calling the throttle API when the page's CDP session is already dead — browser crashed, target destroyed, or context/page closing at that moment.","commonSituations":"Simulating slow 3G in tests whose pages navigate aggressively (target process swaps during goto while throttling applies); throttling set up late in the iteration; throttling after an earlier crash made every CDP call fail.","solutions":["Apply the network profile at context creation so it is configured once on a live session","If throttling per phase, ensure the page is open and idle (not mid-navigation) when it changes","Investigate the first failure in DEBUG=k6-browser logs — this message wraps a session-level problem","Keep k6 and its bundled chromium in sync; version skew can reject the EmulateNetworkConditions parameters"],"exampleFix":"// before\nconst ctx = browser.newContext();\nconst page = await ctx.newPage();\nawait page.close();\nawait ctx.setNetworkProfile ? null : null; // throttling after teardown\n\n// after\nconst ctx = browser.newContext({ networkProfile: { latency: 400, download: 500*1024, upload: 500*1024 } });\nconst page = await ctx.newPage();\nawait page.goto('https://test.k6.io/');","handlingStrategy":"validation","validationCode":"// Prefer setting the profile once at creation; nothing to guard mid-run\nconst ctx = browser.newContext({ networkProfile: { latency: 400, download: 512000, upload: 512000 } });","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Apply networkProfile at context creation instead of switching profiles mid-flight","If profiles must change, do it between settled page states, not during navigation","Keep k6 and its bundled chromium versions aligned"],"tags":["cdp","browser","throttling","network-emulation","lifecycle"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}