{"record":{"id":"1870a898bd17ea91","repo":"NativeScript/NativeScript","slug":"one-networkdomaindebugger-may-be-enabled-at-a-time-1870a8","errorCode":null,"errorMessage":"One NetworkDomainDebugger may be enabled at a time.","messagePattern":"One NetworkDomainDebugger may be enabled at a time\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/debugger/webinspector-network.ios.ts","lineNumber":145,"sourceCode":"\n\tconstructor() {\n\t\tthis.events = new inspectorCommands.NetworkDomain.NetworkFrontend();\n\n\t\t// By default start enabled because we can miss the \"enable\" event when\n\t\t// running with `--debug-brk` -- the frontend will send it before we've been created\n\t\tthis.enable();\n\t}\n\n\tget enabled(): boolean {\n\t\treturn this._enabled;\n\t}\n\n\t/**\n\t * Enables network tracking, network events will now be delivered to the client.\n\t */\n\tenable(): void {\n\t\tif (debuggerDomains.getNetwork()) {\n\t\t\tthrow new Error('One NetworkDomainDebugger may be enabled at a time.');\n\t\t} else {\n\t\t\tdebuggerDomains.setNetwork(this);\n\t\t}\n\t\tthis._enabled = true;\n\t}\n\n\t/**\n\t * Disables network tracking, prevents network events from being sent to the client.\n\t */\n\tdisable(): void {\n\t\tif (debuggerDomains.getNetwork() === this) {\n\t\t\tdebuggerDomains.setNetwork(null);\n\t\t}\n\t\tthis._enabled = false;\n\t}\n\n\t/**\n\t * Specifies whether to always send extra HTTP headers with the requests from this page.","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/NativeScript/NativeScript/blob/6800aefa6511d23ddad8beb38ccc8541c5e91628/packages/core/debugger/webinspector-network.ios.ts#L127-L163","documentation":"On iOS the NetworkDomainDebugger (webinspector network domain) also permits only one enabled instance at a time. enable() throws when debuggerDomains.getNetwork() already returns a registered debugger. This enforces a single receiver of webinspector network events.","triggerScenarios":"Calling enable() on a second NetworkDomainDebugger while the first remains enabled; the constructor auto-enables, so instantiating two debuggers for the same client/session throws; re-initializing after a page reload without disabling the prior instance.","commonSituations":"Hot reload recreating devtools clients on iOS; multiple debug sessions (e.g. Safari inspector and app inspector both creating instances); app re-entry from background rebuilding the inspector without teardown.","solutions":["Use a single shared NetworkDomainDebugger instance across the app","Disable the existing debugger (disable()) before enabling a new one","Skip re-enabling if debuggerDomains already reports an active network debugger","Clear registry state on hot reload before reconstruction"],"exampleFix":"// before\nconst dbg = new NetworkDomainDebugger(client);\n// after\nconst existing = NetworkDomainDebugger.getInstance?.();\nconst dbg = existing ?? new NetworkDomainDebugger(client);","handlingStrategy":"try-catch","validationCode":"let instance: NetworkDomainDebugger | null = null;\nfunction getDebugger(client: Client) {\n  if (!instance) instance = new NetworkDomainDebugger(client);\n  return instance;\n}","typeGuard":"function isDebuggerActive(): boolean {\n  return typeof debuggerDomains !== 'undefined' && debuggerDomains.getNetwork() != null;\n}","tryCatchPattern":"try {\n  dbg.enable();\n} catch (e) {\n  if (/One NetworkDomainDebugger/.test(e.message)) return debuggerDomains.getNetwork();\n  throw e;\n}","preventionTips":["Centralize debugger creation in one module","Disable the previous instance before creating a new one on hot reload","Never enable two debuggers for the same client/session"],"tags":["debugger","network","ios","lifecycle"],"backgroundTag":"singleton-already-enabled","analyzedSha":"6800aefa6511d23ddad8beb38ccc8541c5e91628","analyzedAt":"2026-08-30T20:04:56.809Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}