{"record":{"id":"b3ecde3653ca102b","repo":"jackwener/OpenCLI","slug":"could-not-detect-the-logged-in-twitter-x-profile-l","errorCode":null,"errorMessage":"Could not detect the logged-in Twitter/X profile link","messagePattern":"Could not detect the logged-in Twitter/X profile link","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/twitter/auth.js","lineNumber":65,"sourceCode":"    }\n  }\n  const tail = samples.slice(-SCREEN_NAME_AGREEMENTS);\n  const username = tail[0] || '';\n  return username && tail.every((sample) => sample === username) ? username : '';\n}\n\nasync function verifyTwitterIdentity(page, { phase } = {}) {\n  if (!await hasTwitterSessionCookies(page)) {\n    throw new AuthRequiredError('x.com', 'Twitter/X auth cookies are missing');\n  }\n  await page.goto('https://x.com/home');\n  await page.wait({ selector: '[data-testid=\"primaryColumn\"]' }).catch(() => { });\n  // Login polls repeat every ~2s; they keep the single read and skip the #2252 settle loop.\n  const username = phase === 'poll'\n    ? await readScreenName(page)\n    : await readSettledScreenName(page);\n  if (!username) {\n    throw new AuthRequiredError('x.com', 'Could not detect the logged-in Twitter/X profile link');\n  }\n  return { username, url: `https://x.com/${username}` };\n}\n\nregisterSiteAuthCommands({\n  site: 'twitter',\n  domain: 'x.com',\n  loginUrl: 'https://x.com/i/flow/login',\n  columns: ['username', 'url'],\n  quickCheck: hasTwitterSessionCookies,\n  verify: verifyTwitterIdentity,\n  poll: async (page, options) => {\n    if (!await hasTwitterSessionCookies(page)) {\n      throw new AuthRequiredError('x.com', 'Waiting for Twitter/X auth cookies');\n    }\n    return verifyTwitterIdentity(page, options);\n  },\n});","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/twitter/auth.js#L47-L83","documentation":"After confirming session cookies exist, verifyTwitterIdentity reads the screen name (via readScreenName or readSettledScreenName). If the normalized username comes back empty, the logged-in profile link could not be detected, and it throws AuthRequiredError('x.com', 'Could not detect the logged-in Twitter/X profile link'). Cookies exist but identity is unverifiable, so the CLI treats it as an auth problem.","triggerScenarios":"hasTwitterSessionCookies passes but readScreenName/readSettledScreenName returns '' — profile link missing, href empty, or screen name not stable across settle samples.","commonSituations":"x.com redirects to the login flow despite stale cookies (session invalid server-side), the home page fails to render the primary column/nav bar (slow network, A/B test), or Twitter DOM changes moved the AppTabBar_Profile_Link selector.","solutions":["Log out and log back in to x.com so the session is genuinely valid, then retry.","Increase the settle patience by retrying the command; slow page loads can leave the profile link unread.","Verify in the controlled browser that x.com shows the logged-in nav bar with your profile link.","Update the CLI if Twitter changed the data-testid attributes the probe relies on."],"exampleFix":"// before\nawait page.goto('https://x.com/home');\nconst { username } = await verifyTwitterIdentity(page);\n// after\nawait page.goto('https://x.com/home');\nlet identity;\ntry { identity = await verifyTwitterIdentity(page); }\ncatch (e) { await loginX(); identity = await verifyTwitterIdentity(page); }","handlingStrategy":"fallback","validationCode":"await page.goto('https://x.com/home');\nconst profileLink = await page.waitForSelector('a[data-testid=\"AppTabBar_Profile_Link\"]', { timeout: 8000 }).catch(() => null);\nif (!profileLink) await reloginX();","typeGuard":null,"tryCatchPattern":"try {\n  identity = await verifyTwitterIdentity(page, { phase: 'verify' });\n} catch (e) {\n  if (/profile link/.test(e.message)) {\n    await reloginX(); // stale session: cookies exist but are invalid server-side\n    identity = await verifyTwitterIdentity(page, { phase: 'verify' });\n  } else throw e;\n}","preventionTips":["If cookies exist but detection fails, assume a stale session and re-login","Give the home page time to render the primary column before probing","Retry once on slow networks before treating it as an auth failure","Keep the CLI updated for Twitter DOM/data-testid changes"],"tags":["authentication","dom-probe","screen-name"],"backgroundTag":"login-detection-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}