grafana/k6 · error
throttling network: %w
Error message
throttling network: %w
What it means
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.
Source
Thrown at internal/js/modules/k6/browser/common/network_manager.go:1082
return nil
}
// ThrottleNetwork changes the network attributes in chrome to simulate slower
// networks e.g. a slow 3G connection.
func (m *NetworkManager) ThrottleNetwork(networkProfile NetworkProfile) error {
if m.networkProfile == networkProfile {
return nil
}
m.networkProfile = networkProfile
action := network.EmulateNetworkConditions(
m.offline,
m.networkProfile.Latency,
m.networkProfile.Download,
m.networkProfile.Upload,
)
if err := action.Do(cdp.WithExecutor(m.ctx, m.session)); err != nil {
return fmt.Errorf("throttling network: %w", err)
}
return nil
}
// SetUserAgent overrides the browser user agent string.
func (m *NetworkManager) SetUserAgent(userAgent string) {
action := emulation.SetUserAgentOverride(userAgent)
if err := action.Do(cdp.WithExecutor(m.ctx, m.session)); err != nil {
k6ext.Panicf(m.ctx, "setting user agent: %w", err)
}
}
// SetCacheEnabled toggles cache on/off.
func (m *NetworkManager) SetCacheEnabled(enabled bool) {
m.userCacheDisabled = !enabled
if err := m.updateProtocolCacheDisabled(); err != nil {
k6ext.Panicf(m.ctx, "%v", err)View on GitHub (pinned to 93accf6570)
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
Example fix
// before
const ctx = browser.newContext();
const page = await ctx.newPage();
await page.close();
await ctx.setNetworkProfile ? null : null; // throttling after teardown
// after
const ctx = browser.newContext({ networkProfile: { latency: 400, download: 500*1024, upload: 500*1024 } });
const page = await ctx.newPage();
await page.goto('https://test.k6.io/'); Defensive patterns
Strategy: validation
Validate before calling
// Prefer setting the profile once at creation; nothing to guard mid-run
const ctx = browser.newContext({ networkProfile: { latency: 400, download: 512000, upload: 512000 } }); Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- emulating network conditions: %w
- attaching new page: %w
- selectHandle.dispose: %w
- attaching worker target ID %v to session ID %v: %w
- disposing element with ID %s: %w
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/290dee407694053c.
Report an issue: GitHub.