grafana/k6 · error
updating offline mode for frame %v: %w
Error message
updating offline mode for frame %v: %w
What it means
The offline browser-context option and context.setOffline() are applied per frame session through networkManager.SetOfflineMode (CDP network emulation). This error means that command failed while switching the frame's target in or out of offline mode.
Source
Thrown at internal/js/modules/k6/browser/common/frame_session.go:1193
func (fs *FrameSession) updateHTTPCredentials(initial bool) error {
fs.logger.Debugf("NewFrameSession:updateHttpCredentials", "sid:%v tid:%v", fs.session.ID(), fs.targetID)
credentials := fs.page.browserCtx.opts.HTTPCredentials
if !initial || !credentials.IsEmpty() {
return fs.networkManager.Authenticate(credentials)
}
return nil
}
func (fs *FrameSession) updateOffline(initial bool) error {
fs.logger.Debugf("NewFrameSession:updateOffline", "sid:%v tid:%v", fs.session.ID(), fs.targetID)
offline := fs.page.browserCtx.opts.Offline
if !initial || offline {
if err := fs.networkManager.SetOfflineMode(offline); err != nil {
return fmt.Errorf("updating offline mode for frame %v: %w", fs.targetID, err)
}
}
return nil
}
func (fs *FrameSession) throttleNetwork(networkProfile NetworkProfile) error {
fs.logger.Debugf("NewFrameSession:throttleNetwork", "sid:%v tid:%v", fs.session.ID(), fs.targetID)
return fs.networkManager.ThrottleNetwork(networkProfile)
}
func (fs *FrameSession) throttleCPU(cpuProfile CPUProfile) error {
action := emulation.SetCPUThrottlingRate(cpuProfile.Rate)
if err := action.Do(cdp.WithExecutor(fs.ctx, fs.session)); err != nil {
return fmt.Errorf("throttling CPU: %w", err)
}
View on GitHub (pinned to 93accf6570)
Solutions
- Only call setOffline while the pages in the context are open, and finish offline assertions before closing them
- Guard with page.isClosed() and retry once if the failure coincided with navigation
- If it fails consistently, capture browser stderr: the browser process may be crashing
Example fix
// before
await context.setOffline(true);
await page.goto('https://app.example.com'); // page may already be closing
// after
await context.setOffline(true);
try {
await page.goto('https://app.example.com');
} catch (e) {
// expect net error while offline
}
await context.setOffline(false); Defensive patterns
Strategy: validation
Validate before calling
const pages = context.pages();
if (pages.every((p) => !p.isClosed())) {
await context.setOffline(true);
} Prevention
- Toggle offline only while pages are open
- Restore offline mode to false before closing the context
- Do not toggle offline concurrently with navigation-heavy phases
When it happens
Trigger: Calling browserContext.setOffline(true/false) or creating a context with offline set, when the frame's target or CDP session is gone: page already closed, browser disconnected, or the call racing with navigation/teardown.
Common situations: Simulating connectivity loss mid-test; toggling offline near the end of an iteration before context.close(); pages that close themselves (window.close, target=_blank flow); flaky CI browser instances.
Related errors
- errorText
- setting offline status to %t for the browser context ID %s:
- updating extra HTTP headers: %w
- fetching response body: %w
- getting response body: %w
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/753dc3d384f6aa6f.
Report an issue: GitHub.