{"record":{"id":"f2e8a205b6998654","repo":"jackwener/OpenCLI","slug":"auth-required-facebook-com-redirected-to-login","errorCode":null,"errorMessage":"AUTH_REQUIRED: facebook.com redirected to login","messagePattern":"AUTH_REQUIRED: facebook\\.com redirected to login","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clis/facebook/notifications.js","lineNumber":248,"sourceCode":"            text,\n            time,\n            url: href,\n            notif_id,\n            notif_type,\n        });\n    }\n    return out;\n}\n\nexport function buildNotificationsScript(limit) {\n    return `\n(async () => {\n  const FB_HOST = ${JSON.stringify(FB_HOST)};\n  const MARK_AS_READ_PREFIXES = ${JSON.stringify(MARK_AS_READ_PREFIXES)};\n  const UNREAD_BADGE_LABELS = ${JSON.stringify(UNREAD_BADGE_LABELS)};\n  ${isFacebookAuthRedirectPath.toString()}\n  if (isFacebookAuthRedirectPath(window.location.pathname || '')) {\n    throw new Error('AUTH_REQUIRED: facebook.com redirected to login');\n  }\n  ${stripMarkAsReadPrefix.toString()}\n  ${stripAnchorChrome.toString()}\n  ${parseNotifQuery.toString()}\n  ${extractNotificationRowsFromDoc.toString()}\n  // Wait briefly for [role=\"listitem\"] rows to render in case the SPA\n  // is still hydrating. 8s ceiling keeps a slow network from hanging\n  // the command — empty list after that surfaces as EmptyResultError\n  // on the Node side.\n  const start = Date.now();\n  while (document.querySelectorAll('[role=\"listitem\"]').length === 0 && Date.now() - start < 8000) {\n    await new Promise(function(r) { setTimeout(r, 200); });\n  }\n  return extractNotificationRowsFromDoc(document, ${JSON.stringify(limit)}, {\n    stripMark: stripMarkAsReadPrefix,\n    stripChrome: stripAnchorChrome,\n    parseQuery: parseNotifQuery,\n    fbHost: FB_HOST,","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/facebook/notifications.js#L230-L266","documentation":"A plain Error thrown inside the injected browser-side script (buildNotificationsScript) when window.location.pathname matches an auth-redirect path, i.e. facebook.com bounced the navigation to a login page. It is not the user-facing error itself: getFacebookNotifications catches it, matches /AUTH_REQUIRED/, and rethrows as AuthRequiredError('facebook.com', ...).","triggerScenarios":"page.evaluate ran on a page whose URL is a Facebook login/redirect path because the profile's session cookies were missing or expired when visiting /notifications.","commonSituations":"Expired Facebook session; logged out of the managed Chrome profile; Facebook forced re-auth after password change/security challenge; running against a profile that never logged in to facebook.com.","solutions":["Open the managed Chrome browser and log in to Facebook, then retry the notifications command","Verify /notifications loads (no redirect to login) in the profile browser","Complete any Facebook security/2FA challenge that invalidated the session","If sessions keep expiring, check cookie persistence (user-data-dir) in the browser wrapper"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const onLoginRedirect = await page.evaluate(String.raw`(() => /login|checkpoint/.test(window.location.pathname))()`);\nif (onLoginRedirect) throw new Error('AUTH_REQUIRED: facebook.com redirected to login');","typeGuard":null,"tryCatchPattern":"try {\n  const rows = await getFacebookNotifications(page, args);\n} catch (e) {\n  if (e.name === 'AuthRequiredError' && /facebook\\.com/.test(e.message)) {\n    await openBrowserAndLogin('facebook.com');\n  } else throw e;\n}","preventionTips":["Keep Facebook sessions refreshed in the managed profile","Detect login redirects before running scrape scripts","Complete security/2FA checkpoints promptly","Persist cookies via a stable user-data-dir"],"tags":["auth","session-redirect","facebook"],"backgroundTag":"auth-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}