jackwener/OpenCLI · critical · Error
Cannot connect to Antigravity at ${endpoint}. 1. Make sure
Error message
Cannot connect to Antigravity at ${endpoint}.
1. Make sure Antigravity is running
2. Launch with: --remote-debugging-port=9234 What it means
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.
Source
Thrown at clis/antigravity/serve.js:435
// List available targets for debugging
try {
const res = await fetch(`${endpoint.replace(/\/$/, '')}/json`);
const targets = await res.json();
const pages = targets.filter(t => t.type === 'page');
console.error(`[serve] Available targets: ${pages.map(t => `"${t.title}"`).join(', ')}`);
}
catch { /* ignore */ }
console.error(`[serve] Connecting via CDP (target pattern: "${process.env.OPENCLI_CDP_TARGET}")...`);
cdp = new CDPBridge();
try {
page = await cdp.connect({ timeout: 15_000, cdpEndpoint: endpoint });
}
catch (err) {
cdp = null;
const errMsg = getErrorMessage(err);
const cause = err instanceof Error ? err.cause : undefined;
const isRefused = cause?.code === 'ECONNREFUSED' || errMsg.includes('ECONNREFUSED');
throw new Error(isRefused
? `Cannot connect to Antigravity at ${endpoint}.\n` +
' 1. Make sure Antigravity is running\n' +
' 2. Launch with: --remote-debugging-port=9234'
: `CDP connection failed: ${errMsg}`);
}
console.error('[serve] ✅ CDP connected.');
// Quick verification
const hasUI = await page.evaluate(`
(() => !!document.getElementById('conversation') || !!document.getElementById('antigravity.agentSidePanelInputBox'))()
`);
if (!hasUI) {
console.error('[serve] ⚠️ Warning: chat UI elements not found in this target. Try setting OPENCLI_CDP_TARGET to the correct window title.');
}
return page;
}
const server = createServer(async (req, res) => {
// CORS preflight
if (req.method === 'OPTIONS') {View on GitHub (pinned to 49907e53dc)
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)
Example fix
// before antigravity // after antigravity --remote-debugging-port=9234
Defensive patterns
Strategy: try-catch
Validate before calling
async function cdpReachable(endpoint) {
try {
const res = await fetch(`http://${endpoint}/json/version`);
return res.ok;
} catch { return false; }
}
if (!await cdpReachable('127.0.0.1:9234')) {
throw new Error('Start Antigravity with --remote-debugging-port=9234 first');
} Try / catch
try {
await client.connect(endpoint);
} catch (err) {
if (String(err?.cause?.code || err.message).includes('ECONNREFUSED')) {
console.error('Antigravity not reachable. Run: antigravity --remote-debugging-port=9234');
process.exit(1);
}
throw err;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- 字幕获取失败: ${err?.message || err}
- Failed to fetch CDP targets: HTTP ${response.status}
- CDP not reachable at ${manualEndpoint}
- 12306 queryByTrainNo returned HTTP ${resp.status}
- 12306 queryByTrainNo returned non-JSON body
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/cd2f2be4b87aeca9.
Report an issue: GitHub.