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;
	}

	// -------------------------------------------------------------------------
	// Private

View on GitHub (pinned to 5ac6606e81)

Solutions

  1. Call browser_connect first and await it before issuing any browser tool.
  2. Ensure your tool-dispatch layer gates on connection.isConnected === true.
  3. 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

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


AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12). Data as JSON: /api/errors/bf1e09e31d67e1cc. Report an issue: GitHub.