{"record":{"id":"dad5c9b3e1e9297d","repo":"jackwener/OpenCLI","slug":"gmail-thread-navigation-failed","errorCode":null,"errorMessage":"Gmail thread navigation failed","messagePattern":"Gmail thread navigation failed","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/gmail/utils.js","lineNumber":592,"sourceCode":"    const row = document.querySelector('[data-legacy-thread-id=\"${legacyId}\"]');\n    if (!row) return { found: false };\n    const clickable = row.querySelector('.y6, .bog, td:nth-child(5)') || row;\n    const before = location.href;\n    clickable.click();\n    await new Promise((resolve) => setTimeout(resolve, 150));\n    const rect = clickable.getBoundingClientRect();\n    return { found: true, changed: location.href !== before, x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 };\n  }`), 'thread row lookup');\n  if (targetState?.found && !targetState.changed && typeof page.nativeClick === 'function') {\n    await page.nativeClick(targetState.x, targetState.y);\n  } else if (!targetState?.found) {\n    const navigated = unwrapBrowserResult(await page.evaluate(`() => {\n    const target = ${JSON.stringify(`#all/${legacyId}`)};\n    if (window.location.hash === target) window.location.hash = '#inbox';\n    setTimeout(() => { window.location.hash = target; }, 50);\n    return true;\n  }`), 'thread navigation');\n    if (navigated !== true) throw new CommandExecutionError('Gmail thread navigation failed');\n  }\n  let messages = [];\n  try {\n    const bodies = await waitGmailCaptures(page, 'fd', 'thread', 3);\n    messages = bodies.flatMap(parseFetchData);\n  } catch (error) {\n    if (!(error instanceof TimeoutError)) throw error;\n    await page.sleep(0.5);\n    messages = await renderedThread(page, target);\n    if (messages.length === 0) throw error;\n  }\n  const unique = [...new Map(messages.map((message) => [message.messageId, message])).values()];\n  if (unique.length === 0) {\n    throw new EmptyResultError('gmail thread', `No messages found for thread ${target}`);\n  }\n  return unique;\n}\n","sourceCodeStart":574,"sourceCodeEnd":610,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/gmail/utils.js#L574-L610","documentation":"fetchThread() navigates via a hash change to '#all/<legacyId>' inside page.evaluate; if the wrapper (unwrapBrowserResult) returns anything other than true, the library throws CommandExecutionError 'Gmail thread navigation failed'. It signals the in-page navigation script did not complete as expected.","triggerScenarios":"The evaluate call fails or returns a wrapped error result; the browser context is unresponsive or the page navigated away mid-call; Gmail rejected the hash change (invalid id or blocked navigation).","commonSituations":"Stale/expired Gmail session where navigation is redirected to login; browser tab closed or crashed; extension or CSP interfering with hash navigation; a race where the page reloads during evaluate.","solutions":["Re-authenticate / ensure the Gmail session is logged in, then retry","Retry the fetch once — transient races resolve on a second attempt","Verify the page is on Gmail (correct account, not a login or error page)","Check browser console for script errors blocking the evaluate"],"exampleFix":"// before\nconst thread = await fetchThread(page, threadId); // one-shot\n// after\nlet thread;\ntry { thread = await fetchThread(page, threadId); }\ncatch (e) {\n  if (e instanceof CommandExecutionError) { await page.reload(); thread = await fetchThread(page, threadId); }\n  else throw e;\n}","handlingStrategy":"retry","validationCode":"const hash = await page.evaluate('() => window.location.hash');\nif (!hash || !hash.includes('mail.google.com') === false) /* on Gmail */;","typeGuard":"null","tryCatchPattern":"try { thread = await fetchThread(page, id); }\ncatch (e) { if (e instanceof CommandExecutionError && e.message === 'Gmail thread navigation failed') { await page.reload(); thread = await fetchThread(page, id); } else throw e; }","preventionTips":["Ensure an active, logged-in Gmail session before fetching","Retry once after a reload — navigation races are usually transient","Avoid navigating the tab elsewhere while automation is running"],"tags":["navigation","gmail","ui-automation"],"backgroundTag":"page-navigation-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}