{"record":{"id":"7f1749c7aa21947a","repo":"n8n-io/n8n","slug":"browser-connection-lost-the-browser-extension-dis","errorCode":null,"errorMessage":"Browser connection lost: The browser extension disconnected","messagePattern":"Browser connection lost: The browser extension disconnected","errorType":"exception","errorClass":"ConnectionLostError","httpStatus":null,"severity":"critical","filePath":"packages/@n8n/mcp-browser/src/cdp-relay.ts","lineNumber":433,"sourceCode":"\t\t\t\tconst tabs = await this.listTabs();\n\t\t\t\treturn {\n\t\t\t\t\ttargetInfos: tabs.map((entry) => ({\n\t\t\t\t\t\ttargetId: entry.id,\n\t\t\t\t\t\ttype: 'page',\n\t\t\t\t\t\ttitle: entry.title,\n\t\t\t\t\t\turl: entry.url,\n\t\t\t\t\t\tattached: false,\n\t\t\t\t\t\tbrowserContextId: this.browserContextId,\n\t\t\t\t\t})),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tcase 'Target.setDiscoverTargets':\n\t\t\t\treturn {};\n\n\t\t\tcase 'Target.attachToTarget': {\n\t\t\t\tconst targetId = (params as { targetId: string })?.targetId;\n\t\t\t\tif (!this.extensionConn) throw new ConnectionLostError('extension_disconnected');\n\t\t\t\tawait this.extensionConn.send('attachTab', { id: targetId });\n\t\t\t\treturn { sessionId: targetId };\n\t\t\t}\n\n\t\t\tcase 'Target.setAutoAttach': {\n\t\t\t\t// Child session auto-attach: forward to extension so Chrome attaches to iframes\n\t\t\t\tif (sessionId) {\n\t\t\t\t\treturn await this.forwardToExtension(method, params, sessionId);\n\t\t\t\t}\n\n\t\t\t\t// Root-level: forward to extension (applies to all attached tabs) AND list tabs for cache\n\t\t\t\tlog.debug('Target.setAutoAttach: forwarding to extension and listing tabs');\n\t\t\t\tawait this.forwardToExtension(method, params, sessionId);\n\n\t\t\t\tconst { tabs } = (await this.extensionConn!.send('listRegisteredTabs', {})) as {\n\t\t\t\t\ttabs: Array<{ id: string; title: string; url: string }>;\n\t\t\t\t};\n\t\t\t\tlog.debug('listRegisteredTabs result:', tabs.length, 'tabs');","sourceCodeStart":415,"sourceCodeEnd":451,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/mcp-browser/src/cdp-relay.ts#L415-L451","documentation":"ConnectionLostError('extension_disconnected') is thrown in the Target.attachToTarget CDP handler when this.extensionConn is null. The relay translates Playwright's CDP Target.attachToTarget into an extension 'attachTab' message; if the extension WebSocket is gone, the translation cannot proceed. This indicates the extension side of the bridge dropped.","triggerScenarios":"Playwright issues Target.attachToTarget (during page auto-attach or explicit attach) after the extension connection was closed — e.g. the extension was uninstalled, the browser was quit, or the WebSocket closed and extensionConn was nulled on close.","commonSituations":"User closed the browser while a session was active. Extension crashed or was reloaded. Network interruption dropped the WebSocket and handleClose() nulled extensionConn. Long-idle session where the extension's service worker was evicted.","solutions":["Call browser_disconnect then browser_connect to re-establish the extension bridge.","Ensure the n8n AI Browser Bridge extension is installed, enabled, and not suspended (Chrome service-worker eviction).","Keep the session active with periodic interaction to prevent service-worker suspension."],"exampleFix":"// before — operating after extension dropped\nawait connection.getConnection(); // ConnectionLostError propagates\n\n// after — reconnect\nawait connection.disconnect();\nawait connection.connect();","handlingStrategy":"retry","validationCode":"if (!relay.extensionConn) { await connection.disconnect(); await connection.connect(); }","typeGuard":"function extensionAlive(relay: CdpRelay): boolean {\n  return relay.extensionConn !== null;\n}","tryCatchPattern":"try {\n  await relay.handleCdp('Target.attachToTarget', params);\n} catch (e) {\n  if (e instanceof ConnectionLostError) {\n    await connection.disconnect();\n    await connection.connect();\n    await relay.handleCdp('Target.attachToTarget', params);\n  } else throw e;\n}","preventionTips":["Monitor the extension WebSocket close event and proactively reconnect.","Keep the extension service worker alive with periodic activity.","Surface disconnect to the user immediately rather than letting commands fail."],"tags":["connection-lost","extension","cdp","websocket"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}