Files
wehub-resource-sync 9b395f5cc3
E2E Headed Chrome / e2e-headed (macos-15) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (ubuntu-latest) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (windows-latest) (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / unit-test (push) Has been cancelled
CI / bun-test (push) Has been cancelled
CI / adapter-test (push) Has been cancelled
CI / smoke-test (macos-latest) (push) Has been cancelled
CI / smoke-test (ubuntu-latest) (push) Has been cancelled
Security Audit / audit (push) Has been cancelled
Build Chrome Extension / build (push) Has been cancelled
Trigger Website Rebuild (Docs Updated) / dispatch (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:39:48 +08:00

44 lines
1.7 KiB
JavaScript

import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';
import { registerSiteAuthCommands } from '../_shared/site-auth.js';
async function hasFacebookCUserCookie(page) {
const cookies = await page.getCookies({ url: 'https://www.facebook.com' });
return cookies.some(c => c.name === 'c_user' && c.value);
}
async function verifyFacebookIdentity(page) {
if (!await hasFacebookCUserCookie(page)) {
throw new AuthRequiredError('www.facebook.com', 'Facebook c_user cookie missing — anonymous session');
}
const cookies = await page.getCookies({ url: 'https://www.facebook.com' });
const cUser = cookies.find(c => c.name === 'c_user')?.value || '';
await page.goto('https://www.facebook.com/me');
await page.wait(2);
const finalUrl = await page.evaluate(`location.href`);
const vanityMatch = String(finalUrl || '').match(/facebook\.com\/([^/?#]+)\/?(?:$|[?#])/);
const vanity = vanityMatch?.[1] || '';
if (!vanity || vanity === 'login.php' || vanity === 'checkpoint') {
throw new AuthRequiredError('www.facebook.com', `Facebook /me redirected to ${finalUrl} — logged out or in checkpoint`);
}
return {
user_id: String(cUser),
vanity: String(vanity),
profile_url: `https://www.facebook.com/${vanity}/`,
};
}
registerSiteAuthCommands({
site: 'facebook',
domain: 'facebook.com',
loginUrl: 'https://www.facebook.com/login.php',
columns: ['user_id', 'vanity', 'profile_url'],
quickCheck: hasFacebookCUserCookie,
verify: verifyFacebookIdentity,
poll: async (page) => {
if (!await hasFacebookCUserCookie(page)) {
throw new AuthRequiredError('www.facebook.com', 'Waiting for Facebook c_user cookie');
}
return verifyFacebookIdentity(page);
},
});