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
- Re-run the ask and avoid navigating the tab while waiting
- Re-authenticate if a login redirect happened, then retry
- Pin the automation to a dedicated tab/profile so nothing else navigates it
- 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
- Never navigate the shared tab while an ask wait is in flight
- Run each ask in a dedicated page/tab
- Handle login redirects by re-authenticating before retrying
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
- ChatGPT deep-research-result did not stay on requested conve
- ChatGPT deep-research-result conversation mismatch: expected
- ChatGPT did not open the requested project ${id}. Current UR
- 1688 ${action} navigation lost the current browser target
- 字幕 URL 非法: ${finalUrl}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/7135f984f2767c15.
Report an issue: GitHub.