Skip to content

[Bug]: OpenClaw Browser Relay crashing #8468

@sweihub

Description

@sweihub

The chrome extension is crashing frequently, and cannot be enabled with much success, here's the bug report made by OpenClaw


🐛 Bug Analysis Report

🔴 Critical Issues

1. Missing chrome.runtime.onStartup Handler

Location: /Users/swei/.openclaw/browser/chrome-extension/background.js (line 380-383)

chrome.action.onClicked.addListener(() => void connectOrToggleForActiveTab())
chrome.runtime.onInstalled.addListener(() => {
  void chrome.runtime.openOptionsPage()
})

Problem:

  • When Chrome restarts, the extension does NOT automatically reconnect to the relay server
  • User must manually click the icon to re-attach
  • No chrome.runtime.onStartup handler exists to auto-recover

Impact: High - Extension appears "broken" after browser restart


2. No Automatic Reconnection on WebSocket Failures

Location: Lines 45-83 (ensureRelayConnection())

Problem:

if (relayWs && relayWs.readyState === WebSocket.OPEN) return
if (relayConnectPromise) return await relayConnectPromise
  • Only retries via relayConnectPromise
  • No background retry loop
  • If WebSocket connection fails permanently (network hiccups, relay server crash), extension stays disconnected

Impact: High - Manual intervention required


3. No Error Recovery After Debugger Detach

Location: Lines 245-275

Problem:

async function onDebuggerDetach(source, reason) {
  const tabId = source.tabId
  if (!tabId) return
  if (!tabs.has(tabId)) return
  void detachTab(tabId, reason)
}
  • Simply detaches and removes from state
  • No reconnect attempt
  • If debugger detaches unexpectedly (tab navigation, Chrome crash recovery, system sleep), user must manually re-attach

Impact: Medium - Fragile user experience


4. Service Worker Suspended State

Location: manifest.json and background.js header

Problem:

// manifest.json
"background": { "service_worker": "background.js", "type": "module" }

// background.js
const DEFAULT_PORT = 18792
  • Service Workers in Chrome can be suspended when inactive
  • Relies on chrome.runtime.onStartup to wake up, but that handler is missing
  • Slight delay before auto-reconnection may be missed by WebSocket heartbeat

Impact: Low-Medium - Background state not preserved


📋 Additional Observations

  1. No Persistent Connection State - No localStorage/database backup of attached tabs
  2. No Health Check/Keep-alive - WebSocket has ping/pong but no periodic extension self-check
  3. Error Messages Too Silent - Errors caught by catch { // ignore } are invisible to users

💡 Recommended Fixes

Fix 1: Add chrome.runtime.onStartup Handler

chrome.runtime.onStartup.addListener(async () => {
  await ensureRelayConnection()
  const [active] = await chrome.tabs.query({ active: true, currentWindow: true })
  if (active?.id && !tabs.has(active.id)) {
    tabs.set(active.id, { state: 'connecting' })
    setBadge(active.id, 'connecting')
  }
})

Fix 2: Add Background Reconnection Loop

chrome.alarms.create('reconnect', { periodInMinutes: 1 })
chrome.alarms.onAlarm.addListener(async (alarm) => {
  if (alarm.name === 'reconnect') {
    await ensureRelayConnection()
  }
})

Fix 3: Add Tab Auto-reconnect on Activation

chrome.tabs.onActivated.addListener(async () => {
  await ensureRelayConnection()
})

Would you like me to implement these fixes?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions