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.goto('https://www.reddit.com');
|
||||||
await page.waitForTimeout(3000);
|
await page.waitForTimeout(3000);
|
||||||
|
|
||||||
// Check for login indicators
|
const visibleIndicators = [
|
||||||
const userButton = await page.$('[data-testid="user-drawer-button"]');
|
'[data-testid="user-drawer-button"]',
|
||||||
const avatar = await page.$('[class*="avatar"], [class*="Avatar"]');
|
'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();
|
console.log();
|
||||||
if (isLoggedIn) {
|
if (isLoggedIn) {
|
||||||
|
|||||||
+30
-10
@@ -238,20 +238,40 @@ export class RedditMessagePage {
|
|||||||
// Wait for page to stabilize
|
// Wait for page to stabilize
|
||||||
await this.page.waitForTimeout(2000);
|
await this.page.waitForTimeout(2000);
|
||||||
|
|
||||||
// Check for user menu button (indicates logged in)
|
const visibleIndicators = [
|
||||||
const userButton = await this.page.$('[data-testid="user-drawer-button"]');
|
'[data-testid="user-drawer-button"]',
|
||||||
if (userButton) {
|
'button[aria-label*="User menu"]',
|
||||||
const isVisible = await userButton.isVisible();
|
];
|
||||||
return isVisible;
|
|
||||||
|
for (const selector of visibleIndicators) {
|
||||||
|
const el = this.page.locator(selector).first();
|
||||||
|
if (await el.isVisible().catch(() => false)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alternative check - look for avatar or user icon
|
const attributeIndicators = [
|
||||||
const avatar = await this.page.$('[class*="avatar"], [class*="Avatar"]');
|
'reddit-header-large[is-logged-in="true"]',
|
||||||
if (avatar) {
|
'shreddit-post-overflow-menu[current-user-id]',
|
||||||
return true;
|
];
|
||||||
|
|
||||||
|
for (const selector of attributeIndicators) {
|
||||||
|
const el = await this.page.$(selector);
|
||||||
|
if (el) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return await this.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;
|
||||||
|
}
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error('Failed to check login status:', error);
|
this.logger.error('Failed to check login status:', error);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in new issue
Block a user