diff options
| author | Igor Soarez <igor@soarez.org> | 2026-11-18 10:50:14 +0000 |
|---|---|---|
| committer | Igor Soarez <igor@soarez.org> | 2026-11-18 10:50:14 +0000 |
| commit | 910ac7cd424f6401ea042a84603c42ba055994f8 (patch) | |
| tree | 3ff40da7d14c644428c71cab1b005eca0b186d13 /castle-search/src/search.ts | |
| parent | 39f887e07721c5b3ddd31657e5e8e25e4486d2e5 (diff) | |
castle-search: sign X back in when a search finds it signed out
Username, password, the authenticator code (TOTP) and, when X asks, the
code it emails, read over IMAP. At most one try per 30 minutes, the
password never sent twice, and any unknown step (a captcha) fails saying
a person has to sign in. Details from the file CCS_X_LOGIN_FILE names.
Diffstat (limited to 'castle-search/src/search.ts')
| -rw-r--r-- | castle-search/src/search.ts | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/castle-search/src/search.ts b/castle-search/src/search.ts index 0178349..1ddd523 100644 --- a/castle-search/src/search.ts +++ b/castle-search/src/search.ts @@ -402,16 +402,31 @@ const isGoogleHost = (url: string): boolean => /^https?:\/\/([a-z0-9-]+\.)*googl export const withPage = async <T>( signal: AbortSignal, fn: (page: PageSession, endpoint: string) => Promise<T>, + options: { isolated?: boolean } = {}, ): Promise<T> => { const release = await acquire(signal); try { const conn = await ensureConnection(signal); const endpoint = describeCdpTarget(conn.target); - const page = await PageSession.open(conn, signal); + // isolated: a browser context of its own, with none of the profile's + // cookies, thrown away afterwards with everything in it. + let context: string | undefined; + if (options.isolated) { + const created = await conn.send("Target.createBrowserContext", { disposeOnDetach: true }); + if (typeof created["browserContextId"] !== "string") { + throw new BrowserUnavailableError("Target.createBrowserContext did not return a browserContextId"); + } + context = created["browserContextId"]; + } try { - return await fn(page, endpoint); + const page = await PageSession.open(conn, signal, context); + try { + return await fn(page, endpoint); + } finally { + await page.close(); + } } finally { - await page.close(); + if (context) await conn.send("Target.disposeBrowserContext", { browserContextId: context }).catch(() => {}); } } finally { release(); |
