{"record":{"id":"753dc3d384f6aa6f","repo":"grafana/k6","slug":"updating-offline-mode-for-frame-v-w","errorCode":null,"errorMessage":"updating offline mode for frame %v: %w","messagePattern":"updating offline mode for frame (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/frame_session.go","lineNumber":1193,"sourceCode":"\nfunc (fs *FrameSession) updateHTTPCredentials(initial bool) error {\n\tfs.logger.Debugf(\"NewFrameSession:updateHttpCredentials\", \"sid:%v tid:%v\", fs.session.ID(), fs.targetID)\n\n\tcredentials := fs.page.browserCtx.opts.HTTPCredentials\n\tif !initial || !credentials.IsEmpty() {\n\t\treturn fs.networkManager.Authenticate(credentials)\n\t}\n\n\treturn nil\n}\n\nfunc (fs *FrameSession) updateOffline(initial bool) error {\n\tfs.logger.Debugf(\"NewFrameSession:updateOffline\", \"sid:%v tid:%v\", fs.session.ID(), fs.targetID)\n\n\toffline := fs.page.browserCtx.opts.Offline\n\tif !initial || offline {\n\t\tif err := fs.networkManager.SetOfflineMode(offline); err != nil {\n\t\t\treturn fmt.Errorf(\"updating offline mode for frame %v: %w\", fs.targetID, err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (fs *FrameSession) throttleNetwork(networkProfile NetworkProfile) error {\n\tfs.logger.Debugf(\"NewFrameSession:throttleNetwork\", \"sid:%v tid:%v\", fs.session.ID(), fs.targetID)\n\n\treturn fs.networkManager.ThrottleNetwork(networkProfile)\n}\n\nfunc (fs *FrameSession) throttleCPU(cpuProfile CPUProfile) error {\n\taction := emulation.SetCPUThrottlingRate(cpuProfile.Rate)\n\tif err := action.Do(cdp.WithExecutor(fs.ctx, fs.session)); err != nil {\n\t\treturn fmt.Errorf(\"throttling CPU: %w\", err)\n\t}\n","sourceCodeStart":1175,"sourceCodeEnd":1211,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/frame_session.go#L1175-L1211","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nawait context.setOffline(true);\nawait page.goto('https://app.example.com'); // page may already be closing\n\n// after\nawait context.setOffline(true);\ntry {\n  await page.goto('https://app.example.com');\n} catch (e) {\n  // expect net error while offline\n}\nawait context.setOffline(false);","handlingStrategy":"validation","validationCode":"const pages = context.pages();\nif (pages.every((p) => !p.isClosed())) {\n  await context.setOffline(true);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["browser","network","offline","cdp"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}