From 1ec160881ac0ddf670d7c3568d8c5622a8cb76d7 Mon Sep 17 00:00:00 2001 From: Elisa Carrillo <46950428+queenellie873@users.noreply.github.com> Date: Sun, 25 Oct 2026 18:27:56 -0700 Subject: [PATCH] fix: stop waiting on network idle after 5s when reading job pages Some careers pages never go network idle, so waitForNetworkIdle timed out at 30s and the opportunity was never refined. Cap the wait at 5s and read whatever has rendered. Only TimeoutError is swallowed. --- packages/core/src/infrastructure/puppeteer.ts | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/packages/core/src/infrastructure/puppeteer.ts b/packages/core/src/infrastructure/puppeteer.ts index 6e67bca38..8c521b1d2 100644 --- a/packages/core/src/infrastructure/puppeteer.ts +++ b/packages/core/src/infrastructure/puppeteer.ts @@ -1,4 +1,8 @@ -import puppeteer, { type Browser, type Page } from 'puppeteer-core'; +import puppeteer, { + type Browser, + type Page, + TimeoutError, +} from 'puppeteer-core'; import UserAgent from 'user-agents'; // Environment Variable(s) @@ -30,13 +34,14 @@ export async function getPageContent(url: string): Promise { waitUntil: 'domcontentloaded', }); - await page.waitForNetworkIdle(); + const idleTimedOut = await waitForIdleOrContinue(page); const content = await page.evaluate(() => { return document.body.innerText; }); console.log('Page content found.', { + idleTimedOut, length: content.length, status: response?.status(), url: url.slice(0, 50) + '...', @@ -48,6 +53,28 @@ export async function getPageContent(url: string): Promise { // Helpers +/** + * Waits up to 5 seconds for the network to go idle. Some sites never go idle + * (e.g. analytics, polling), so if we time out we keep going and read whatever + * has rendered. Any other error is rethrown. + * + * @param page - Page to wait on. + * @returns Whether the wait timed out. + */ +async function waitForIdleOrContinue(page: Page): Promise { + try { + await page.waitForNetworkIdle({ timeout: 5_000 }); + + return false; + } catch (e) { + if (!(e instanceof TimeoutError)) { + throw e; + } + + return true; + } +} + /** * Runs the given function with a new Puppeteer browser instance and page * instance. It sets a random user agent string for the page and closes the