First step toward zero-confirmation direct connect to the user's real Chrome: Chrome 136 killed --remote-debugging-port on the default profile, so the only sanctioned way to drive the user's live logged-in window is an extension using chrome.debugger (same approach as Codex/Claude, whose extensions are closed). Vendors the MIT-licensed openclaw-browser-relay extension into extensions/ab-connect/, rebranded to "agent-browser connect" (NOTICE.md keeps attribution). It already handles the hard parts: chrome.debugger auto-attach all tabs, new-tab auto-attach, MV3 service-worker keepalive (alarms) + reconnect, sessionId↔tab mapping, token auth, and a CDP-over-WebSocket envelope (connect handshake / forwardCDPCommand / forwardCDPEvent / ping-pong). Inert for now — not wired. Next: an abs-daemon relay that speaks this envelope and bridges it to the existing CdpClient (raw CDP), then a `connect` command.
58 lines
1.7 KiB
JavaScript
58 lines
1.7 KiB
JavaScript
const PORT_GUIDANCE = 'Use gateway port + 3 (for gateway 18789, relay is 18792).'
|
|
|
|
function hasCdpVersionShape(data) {
|
|
return !!data && typeof data === 'object' && 'Browser' in data && 'Protocol-Version' in data
|
|
}
|
|
|
|
export function classifyRelayCheckResponse(res, port) {
|
|
if (!res) {
|
|
return { action: 'throw', error: 'No response from service worker' }
|
|
}
|
|
|
|
if (res.status === 401) {
|
|
return { action: 'status', kind: 'error', message: 'Gateway token rejected. Check token and save again.' }
|
|
}
|
|
|
|
if (res.error) {
|
|
return { action: 'throw', error: res.error }
|
|
}
|
|
|
|
if (!res.ok) {
|
|
return { action: 'throw', error: `HTTP ${res.status}` }
|
|
}
|
|
|
|
const contentType = String(res.contentType || '')
|
|
if (!contentType.includes('application/json')) {
|
|
return {
|
|
action: 'status',
|
|
kind: 'error',
|
|
message: `Wrong port: this is likely the gateway, not the relay. ${PORT_GUIDANCE}`,
|
|
}
|
|
}
|
|
|
|
if (!hasCdpVersionShape(res.json)) {
|
|
return {
|
|
action: 'status',
|
|
kind: 'error',
|
|
message: `Wrong port: expected relay /json/version response. ${PORT_GUIDANCE}`,
|
|
}
|
|
}
|
|
|
|
return { action: 'status', kind: 'ok', message: `Relay reachable and authenticated at http://127.0.0.1:${port}/` }
|
|
}
|
|
|
|
export function classifyRelayCheckException(err, port) {
|
|
const message = String(err || '').toLowerCase()
|
|
if (message.includes('json') || message.includes('syntax')) {
|
|
return {
|
|
kind: 'error',
|
|
message: `Wrong port: this is not a relay endpoint. ${PORT_GUIDANCE}`,
|
|
}
|
|
}
|
|
|
|
return {
|
|
kind: 'error',
|
|
message: `Relay not reachable/authenticated at http://127.0.0.1:${port}/. Start OpenClaw browser relay and verify token.`,
|
|
}
|
|
}
|