A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search
fix(workers): Set a timeout on the screenshot call and completely skip it if screenshotting is disabled
Mohamed Bassem6ccdbe59d700
diff --git a/apps/workers/crawlerWorker.ts b/apps/workers/crawlerWorker.tsindex 2dad98b7..376e50ea 100644--- a/apps/workers/crawlerWorker.ts+++ b/apps/workers/crawlerWorker.ts@@ -277,18 +277,31 @@ async function crawlPage(jobId: string, url: string) {logger.info(`[Crawler][${jobId}] Finished waiting for the page to load.`);- const [htmlContent, screenshot] = await Promise.all([- page.content(),- page.screenshot({- // If you change this, you need to change the asset type in the store function.- type: "png",- encoding: "binary",- fullPage: serverConfig.crawler.fullPageScreenshot,- }),- ]);- logger.info(- `[Crawler][${jobId}] Finished capturing page content and a screenshot. FullPageScreenshot: ${serverConfig.crawler.fullPageScreenshot}`,- );+ const htmlContent = await page.content();+ logger.info(`[Crawler][${jobId}] Successfully fetched the page content.`);++ let screenshot: Buffer | undefined = undefined;+ if (serverConfig.crawler.storeScreenshot) {+ screenshot = await Promise.race<Buffer | undefined>([+ page+ .screenshot({+ // If you change this, you need to change the asset type in the store function.+ type: "png",+ encoding: "binary",+ fullPage: serverConfig.crawler.fullPageScreenshot,+ })+ .catch(() => undefined),+ new Promise((f) => setTimeout(f, 5000)),+ ]);+ if (!screenshot) {+ logger.warn(`[Crawler][${jobId}] Failed to capture the screenshot.`);+ } else {+ logger.info(+ `[Crawler][${jobId}] Finished capturing page content and a screenshot. FullPageScreenshot: ${serverConfig.crawler.fullPageScreenshot}`,+ );+ }+ }+return {htmlContent,screenshot,@@ -336,7 +349,7 @@ function extractReadableContent(}async function storeScreenshot(- screenshot: Buffer,+ screenshot: Buffer | undefined,userId: string,jobId: string,) {@@ -346,6 +359,12 @@ async function storeScreenshot();return null;}+ if (!screenshot) {+ logger.info(+ `[Crawler][${jobId}] Skipping storing the screenshot as it's empty.`,+ );+ return null;+ }const assetId = newAssetId();const contentType = "image/png";const fileName = "screenshot.png";