{"record":{"id":"cd2f2be4b87aeca9","repo":"jackwener/OpenCLI","slug":"cannot-connect-to-antigravity-at-endpoint-1","errorCode":null,"errorMessage":"Cannot connect to Antigravity at ${endpoint}.\n  1. Make sure Antigravity is running\n  2. Launch with: --remote-debugging-port=9234","messagePattern":"Cannot connect to Antigravity at (.+?)\\.\n  1\\. Make sure Antigravity is running\n  2\\. Launch with: --remote-debugging-port=9234","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"clis/antigravity/serve.js","lineNumber":435,"sourceCode":"        // List available targets for debugging\n        try {\n            const res = await fetch(`${endpoint.replace(/\\/$/, '')}/json`);\n            const targets = await res.json();\n            const pages = targets.filter(t => t.type === 'page');\n            console.error(`[serve] Available targets: ${pages.map(t => `\"${t.title}\"`).join(', ')}`);\n        }\n        catch { /* ignore */ }\n        console.error(`[serve] Connecting via CDP (target pattern: \"${process.env.OPENCLI_CDP_TARGET}\")...`);\n        cdp = new CDPBridge();\n        try {\n            page = await cdp.connect({ timeout: 15_000, cdpEndpoint: endpoint });\n        }\n        catch (err) {\n            cdp = null;\n            const errMsg = getErrorMessage(err);\n            const cause = err instanceof Error ? err.cause : undefined;\n            const isRefused = cause?.code === 'ECONNREFUSED' || errMsg.includes('ECONNREFUSED');\n            throw new Error(isRefused\n                ? `Cannot connect to Antigravity at ${endpoint}.\\n` +\n                    '  1. Make sure Antigravity is running\\n' +\n                    '  2. Launch with: --remote-debugging-port=9234'\n                : `CDP connection failed: ${errMsg}`);\n        }\n        console.error('[serve] ✅ CDP connected.');\n        // Quick verification\n        const hasUI = await page.evaluate(`\n      (() => !!document.getElementById('conversation') || !!document.getElementById('antigravity.agentSidePanelInputBox'))()\n    `);\n        if (!hasUI) {\n            console.error('[serve] ⚠️  Warning: chat UI elements not found in this target. Try setting OPENCLI_CDP_TARGET to the correct window title.');\n        }\n        return page;\n    }\n    const server = createServer(async (req, res) => {\n        // CORS preflight\n        if (req.method === 'OPTIONS') {","sourceCodeStart":417,"sourceCodeEnd":453,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/antigravity/serve.js#L417-L453","documentation":"ensureConnected wraps CDP (Chrome DevTools Protocol) connection setup; when the underlying connection fails with ECONNREFUSED it rethrows this actionable error naming the Antigravity debug endpoint. Antigravity isn't listening on the remote-debugging port, so no browser automation can proceed.","triggerScenarios":"ensureConnected attempts the CDP WebSocket/HTTP connect to the endpoint (default port 9234), gets ECONNREFUSED (err.cause.code or message contains 'ECONNREFUSED'), and throws the formatted message; any other connect error becomes 'CDP connection failed: ...' instead.","commonSituations":"Antigravity launched normally without --remote-debugging-port=9234; Antigravity not running at all; wrong endpoint/port configured (env or flag); remote debugging port already bound by another instance then exited; firewall/container networking blocking localhost port; Antigravity still starting when the server connected.","solutions":["Close and relaunch Antigravity with --remote-debugging-port=9234","Confirm Antigravity is fully running (open the window) before starting the serve process","Verify the endpoint/port matches how Antigravity was launched (curl http://127.0.0.1:9234/json/version)","Check that nothing else occupies the port and no firewall blocks it","Wait a few seconds after launching before connecting (startup race)"],"exampleFix":"// before\nantigravity\n// after\nantigravity --remote-debugging-port=9234","handlingStrategy":"try-catch","validationCode":"async function cdpReachable(endpoint) {\n  try {\n    const res = await fetch(`http://${endpoint}/json/version`);\n    return res.ok;\n  } catch { return false; }\n}\nif (!await cdpReachable('127.0.0.1:9234')) {\n  throw new Error('Start Antigravity with --remote-debugging-port=9234 first');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await client.connect(endpoint);\n} catch (err) {\n  if (String(err?.cause?.code || err.message).includes('ECONNREFUSED')) {\n    console.error('Antigravity not reachable. Run: antigravity --remote-debugging-port=9234');\n    process.exit(1);\n  }\n  throw err;\n}","preventionTips":["Always launch Antigravity with --remote-debugging-port=9234","Health-check the CDP endpoint before starting the server","Pin the port and confirm nothing else binds it","Wait for IDE startup before connecting"],"tags":["network","cdp","connection-refused","antigravity"],"backgroundTag":"connection-refused","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}