fix: verify stored sessions from a Reddit page

This commit is contained in:
jjbrunton committed 2026-08-08 20:22:45 +01:00
1 parent 8df2d648dd
commit 5623100e93
2 files changed
+26 -1

No files matched your search

+17 -1
View File
@@ -133,7 +133,14 @@ export class BrowserClient {
/** Returns the username and stable t2 account ID for identity binding. */
async getAuthenticatedIdentity(): Promise<RedditAccountIdentity | null> {
try {
return await this.getRedditIdentity(await this.getPage());
const page = await this.getPage();
if (!isRedditPage(page.url())) {
await page.goto('https://www.reddit.com', {
waitUntil: 'domcontentloaded',
timeout: 30000,
});
}
return await this.getRedditIdentity(page);
} catch {
return null;
}
@@ -212,3 +219,12 @@ export class BrowserClient {
}
}
function isRedditPage(value: string): boolean {
try {
const hostname = new URL(value).hostname.toLowerCase();
return hostname === 'reddit.com' || hostname.endsWith('.reddit.com');
} catch {
return false;
}
}