grafana/k6 · error
emulating network conditions: %w
Error message
emulating network conditions: %w
What it means
The CDP command Network.emulateNetworkConditions failed while toggling offline mode. SetOfflineMode is a no-op when the state is unchanged; the error means the command itself could not be delivered or executed on the page's session.
Source
Thrown at internal/js/modules/k6/browser/common/network_manager.go:1061
return nil
}
// SetOfflineMode toggles offline mode on/off.
func (m *NetworkManager) SetOfflineMode(offline bool) error {
if m.offline == offline {
return nil
}
m.offline = offline
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("emulating network conditions: %w", err)
}
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,View on GitHub (pinned to 93accf6570)
Solutions
- Toggle offline while the page is definitely open, before navigation or after it settles, not around close()
- Do the flip synchronously and await it before issuing goto()/reload()
- If it recurs, look upstream in the logs for the browser/session failure that made the command undeliverable
- Consider context-level network emulation options instead of repeated mid-flight toggles
Example fix
// before
await ctx.setOffline(true);
await page.goto('https://test.k6.io/'); // offline already raced a closed target
// after
await ctx.setOffline(true);
await page.reload(); // page/target alive; emulate applies to live session Defensive patterns
Strategy: try-catch
Validate before calling
if (page.isClosed()) { /* skip: toggling offline on a dead session will fail */ } Try / catch
try {
await ctx.setOffline(true);
} catch (e) {
if (/emulating network conditions/.test(String(e))) return;
throw e;
} Prevention
- Toggle offline only while pages in the context are open and idle
- Avoid toggling inside event handlers or near close()
- Pair each setOffline(true) with a deterministic setOffline(false) before iteration end
When it happens
Trigger: browserContext.setOffline(true/false) (or creating a context with offline: true) when the page session is closed, the browser has crashed, or the target is being destroyed — e.g. toggling offline inside a handler or after close started.
Common situations: Testing offline behavior by flipping setOffline around actions, racing page close at iteration end; offline toggles in loops for flaky-network simulation on a target that navigated cross-process.
Related errors
- throttling network: %w
- attaching new page: %w
- selectHandle.dispose: %w
- attaching worker target ID %v to session ID %v: %w
- updating offline mode for frame %v: %w
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/81275bd4ef4c7138.
Report an issue: GitHub.