jackwener/OpenCLI · error · Error
AUTH_REQUIRED: facebook.com redirected to login
Error message
AUTH_REQUIRED: facebook.com redirected to login
What it means
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', ...).
Source
Thrown at clis/facebook/notifications.js:248
text,
time,
url: href,
notif_id,
notif_type,
});
}
return out;
}
export function buildNotificationsScript(limit) {
return `
(async () => {
const FB_HOST = ${JSON.stringify(FB_HOST)};
const MARK_AS_READ_PREFIXES = ${JSON.stringify(MARK_AS_READ_PREFIXES)};
const UNREAD_BADGE_LABELS = ${JSON.stringify(UNREAD_BADGE_LABELS)};
${isFacebookAuthRedirectPath.toString()}
if (isFacebookAuthRedirectPath(window.location.pathname || '')) {
throw new Error('AUTH_REQUIRED: facebook.com redirected to login');
}
${stripMarkAsReadPrefix.toString()}
${stripAnchorChrome.toString()}
${parseNotifQuery.toString()}
${extractNotificationRowsFromDoc.toString()}
// Wait briefly for [role="listitem"] rows to render in case the SPA
// is still hydrating. 8s ceiling keeps a slow network from hanging
// the command — empty list after that surfaces as EmptyResultError
// on the Node side.
const start = Date.now();
while (document.querySelectorAll('[role="listitem"]').length === 0 && Date.now() - start < 8000) {
await new Promise(function(r) { setTimeout(r, 200); });
}
return extractNotificationRowsFromDoc(document, ${JSON.stringify(limit)}, {
stripMark: stripMarkAsReadPrefix,
stripChrome: stripAnchorChrome,
parseQuery: parseNotifQuery,
fbHost: FB_HOST,View on GitHub (pinned to 49907e53dc)
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
Defensive patterns
Strategy: try-catch
Validate before calling
const onLoginRedirect = await page.evaluate(String.raw`(() => /login|checkpoint/.test(window.location.pathname))()`);
if (onLoginRedirect) throw new Error('AUTH_REQUIRED: facebook.com redirected to login'); Try / catch
try {
const rows = await getFacebookNotifications(page, args);
} catch (e) {
if (e.name === 'AuthRequiredError' && /facebook\.com/.test(e.message)) {
await openBrowserAndLogin('facebook.com');
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Open Chrome and log in to Facebook before retrying.
- facebook.com
- facebook.com
- facebook.com
- 请先在共享 Chrome 完成 1688 登录/验证,再重试(${action})
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/f2e8a205b6998654.
Report an issue: GitHub.