jackwener/OpenCLI · error · CommandExecutionError

ChatGPT navigated away from the target conversation (${optio

Error message

ChatGPT navigated away from the target conversation (${options.conversationUrl}); current URL is ${currentUrl}

What it means

While waiting for an ask/response to stabilize, the library periodically compares the current ChatGPT URL to the conversation URL it is monitoring. If the browser navigated to a different conversation, the polling would read the wrong text, so it throws immediately.

Source

Thrown at clis/chatgpt/utils.js:2215

        const key = responsePairKey(user, assistant);
        if ((currentPairCounts.get(key) || 0) <= (baselinePairCounts.get(key) || 0)) continue;
        return String(assistant.Text || '').trim();
    }
    return '';
}

export async function waitForChatGPTResponse(page, baselineCount, prompt, timeoutSeconds, options = {}) {
    const startTime = Date.now();
    let lastText = '';
    let stableCount = 0;
    const baselinePairCounts = normalizeBaselinePairCounts(options);

    while (Date.now() - startTime < timeoutSeconds * 1000) {
        await page.sleep(3);
        if (options.conversationUrl) {
            const currentUrl = await currentChatGPTUrl(page);
            if (currentUrl && !isSameChatGPTConversation(currentUrl, options.conversationUrl)) {
                throw new CommandExecutionError(
                    `ChatGPT navigated away from the target conversation (${options.conversationUrl}); current URL is ${currentUrl}`,
                );
            }
        }
        if (await isGenerating(page)) {
            stableCount = 0;
            continue;
        }

        const messages = await getVisibleMessages(page, { textOnly: true });
        const candidate = findLatestNewAssistantResponse(messages, prompt, baselinePairCounts);
        if (!candidate || candidate === String(prompt || '').trim()) continue;

        if (candidate === lastText) {
            stableCount += 1;
            if (stableCount >= 2) return candidate;
        } else {
            lastText = candidate;

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-run the ask and avoid navigating the tab while waiting
  2. Re-authenticate if a login redirect happened, then retry
  3. Pin the automation to a dedicated tab/profile so nothing else navigates it
  4. If a fork to a new conversation is expected, use the new URL via isSameChatGPTConversation-aware options or disable the URL guard
Defensive patterns

Strategy: try-catch

Validate before calling

const url = await currentChatGPTUrl(page);
if (options.conversationUrl && !isSameChatGPTConversation(url, options.conversationUrl)) {
  throw new Error('already off the target conversation before waiting');
}

Type guard

function onTargetConversation(currentUrl, targetUrl) { return !!currentUrl && isSameChatGPTConversation(currentUrl, targetUrl); }

Try / catch

try {
  await waitForChatGPTAskResult(page, { conversationUrl });
} catch (e) {
  if (String(e.message).startsWith('ChatGPT navigated away')) {
    // re-authenticate if redirected to login, then restart the ask on a fresh navigation
  } else throw e;
}

Prevention

When it happens

Trigger: During the ask wait loop with options.conversationUrl set, currentChatGPTUrl(page) returns a URL that fails isSameChatGPTConversation — a navigation to another conversation, the home page, or a login redirect occurred mid-wait.

Common situations: Session expired and ChatGPT redirected to login; user or another script navigated the shared tab; clicking a suggestion opened a new conversation; SPA redirect after an error.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/7135f984f2767c15. Report an issue: GitHub.