alibaba/page-agent · error · Error

Hub is not connected. Is the extension running?

Error message

Hub is not connected. Is the extension running?

What it means

HubBridge.executeTask throws when the WebSocket connection to the browser extension hub is not open, i.e. this.connected is false. The bridge cannot send the task, so it fails immediately rather than queueing.

Source

Thrown at packages/mcp/src/hub-bridge.js:85

			})
		})
	}

	get connected() {
		return this.#hub?.readyState === 1
	}

	get busy() {
		return this.#pendingTask !== null
	}

	/**
	 * @param {string} task
	 * @param {Record<string, unknown>} [config]
	 * @returns {Promise<{success: boolean, data: string}>}
	 */
	async executeTask(task, config) {
		if (!this.connected) throw new Error('Hub is not connected. Is the extension running?')
		if (this.#pendingTask) throw new Error('Agent is already running a task.')

		return new Promise((resolve, reject) => {
			this.#pendingTask = { resolve, reject }
			this.#hub.send(JSON.stringify({ type: 'execute', task, config }))
		})
	}

	stopTask() {
		if (this.connected) {
			this.#hub.send(JSON.stringify({ type: 'stop' }))
		}
	}

	// TODO: Add version checking

	/** @param {import('ws').WebSocket} ws */
	#onConnection(ws) {

View on GitHub (pinned to d02db1ee7c)

Solutions

  1. Ensure the extension is installed and running, then re-establish the connection (await connect()) before executeTask
  2. Track the close/disconnect event on the bridge and reconnect before dispatching the next task
  3. Add a connectivity check (bridge.connected) before invoking and surface a actionable message to the user
  4. Retry with backoff if the disconnect was transient (browser restarting)

Example fix

// before
const bridge = new HubBridge()
bridge.connect()
await bridge.executeTask(task) // may run before handshake completes

// after
const bridge = new HubBridge()
await bridge.connect() // wait for connection
if (!bridge.connected) throw new Error('Extension not reachable — is it installed and enabled?')
await bridge.executeTask(task)
Defensive patterns

Strategy: validation

Validate before calling

if (!bridge.connected) {
  await bridge.connect()
}
if (!bridge.connected) {
  throw new Error('Extension hub unreachable — install/enable the extension and retry')
}

Type guard

null

Try / catch

try {
  await bridge.executeTask(task)
} catch (e) {
  if (e instanceof Error && e.message.includes('Hub is not connected')) {
    await bridge.connect() // attempt reconnect once
    return bridge.executeTask(task)
  }
  throw e
}

Prevention

When it happens

Trigger: Calling executeTask() before connect() resolves, after the WebSocket closed (extension reloaded, tab closed, network drop), or when the extension was never installed/enabled so connection never established.

Common situations: Extension updated/reloaded while the MCP server kept running; calling executeTask in a script right after constructing HubBridge without awaiting the connection handshake; extension not installed or the hub port not exposed; browser closed between tasks.

Related errors


AI-assisted analysis of alibaba/page-agent@d02db1ee7c (2026-08-28). Data as JSON: /api/errors/cfdc14de4af1be9a. Report an issue: GitHub.