Update
This commit is contained in:
1 parent
cad1f7b842
commit
2a78f65b09
2 files changed
+69
-14
No files matched your search
+39
-4
@@ -63,11 +63,46 @@ async function manualLogin(): Promise<void> {
|
||||
await page.goto('https://www.reddit.com');
|
||||
await page.waitForTimeout(3000);
|
||||
|
||||
// Check for login indicators
|
||||
const userButton = await page.$('[data-testid="user-drawer-button"]');
|
||||
const avatar = await page.$('[class*="avatar"], [class*="Avatar"]');
|
||||
const visibleIndicators = [
|
||||
'[data-testid="user-drawer-button"]',
|
||||
'button[aria-label*="User menu"]',
|
||||
];
|
||||
|
||||
const isLoggedIn = (userButton && (await userButton.isVisible())) || avatar !== null;
|
||||
let isLoggedIn = false;
|
||||
for (const selector of visibleIndicators) {
|
||||
const el = page.locator(selector).first();
|
||||
if (await el.isVisible().catch(() => false)) {
|
||||
isLoggedIn = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isLoggedIn) {
|
||||
const attributeIndicators = [
|
||||
'reddit-header-large[is-logged-in="true"]',
|
||||
'shreddit-post-overflow-menu[current-user-id]',
|
||||
];
|
||||
for (const selector of attributeIndicators) {
|
||||
const el = await page.$(selector);
|
||||
if (el) {
|
||||
isLoggedIn = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isLoggedIn) {
|
||||
isLoggedIn = await page.evaluate(async () => {
|
||||
try {
|
||||
const res = await fetch('https://www.reddit.com/api/me.json', { credentials: 'include' });
|
||||
if (!res.ok) return false;
|
||||
const data = await res.json();
|
||||
return Boolean(data && data.name);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
console.log();
|
||||
if (isLoggedIn) {
|
||||
|
||||
Reference in new issue
Block a user