n8n-io/n8n · error · NotConnectedError
Not connected to a browser
Error message
Not connected to a browser
What it means
NotConnectedError is thrown by getConnection() when this.state is null and this.disconnectReason is also undefined — the connection was never established (or was cleanly disconnected). This is the 'no session exists' state, distinct from an involuntary drop.
Source
Thrown at packages/@n8n/mcp-browser/src/connection.ts:170
if (!this.state) return; // already disconnected — idempotent
const { adapter } = this.state;
this.state = null;
this.disconnectReason = undefined;
try {
await adapter.close();
} catch {
// Browser may already be dead — that's fine
}
}
getConnection(): ConnectionState {
if (!this.state) {
if (this.disconnectReason) {
throw new ConnectionLostError(this.disconnectReason);
}
throw new NotConnectedError();
}
return this.state;
}
get isConnected(): boolean {
return this.state !== null;
}
async shutdown(): Promise<void> {
await this.disconnect();
}
getResolvedConfig(): ResolvedConfig {
return this.config;
}
// -------------------------------------------------------------------------
// PrivateView on GitHub (pinned to 5ac6606e81)
Solutions
- Call browser_connect first and await it before issuing any browser tool.
- Ensure your tool-dispatch layer gates on connection.isConnected === true.
- After disconnect(), reset any agent state that assumes a live connection.
Example fix
// before — tool before connect const snap = await browserSnapshot(); // getConnection -> NotConnectedError // after — connect first await connection.connect(); const snap = await browserSnapshot();
Defensive patterns
Strategy: validation
Validate before calling
if (!connection.isConnected) { await connection.connect(); }
const conn = connection.getConnection(); Type guard
function isReady(c: BrowserConnection): boolean {
return c.isConnected;
} Try / catch
try {
const conn = connection.getConnection();
} catch (e) {
if (e instanceof NotConnectedError) { await connection.connect(); }
else throw e;
} Prevention
- Always call and await browser_connect before any browser tool.
- Gate the tool dispatcher on isConnected.
- After disconnect(), reset agent state that assumes a live connection.
When it happens
Trigger: Calling any browser tool before browser_connect was ever called, or after a clean browser_disconnect (which clears both state and disconnectReason).
Common situations: Agent skips the connect step and jumps straight to a snapshot or interaction tool. Post-disconnect tool call in a teardown sequence. First-call race where the tool runs before connect resolves.
Related errors
- Already connected to a browser
- Cannot decrease maxIterations when resuming a run. Expected
- Checkpoint for runId ${this.runId} has pending tool calls —
- Model ID is required
- Invalid model ID "${rawId}": expected "provider/model-name"
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/bf1e09e31d67e1cc.
Report an issue: GitHub.