From 5084cb1a851f4e0f009593cf7430e4725cf30373 Mon Sep 17 00:00:00 2001 From: Kelly Date: Sat, 13 Dec 2025 03:28:12 -0700 Subject: [PATCH] fix: Block images/fonts/media in Puppeteer to save bandwidth MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add request interception to all Puppeteer handlers to block unnecessary resources (images, fonts, media, stylesheets). We only need HTML/JS for the session cookie, then the GraphQL JSON response. This was causing 2.4GB of bandwidth from assets2.dutchie.com - every page visit downloaded all product thumbnails, logos, etc. Files updated: - product-discovery-http.ts - entry-point-discovery.ts - store-discovery-http.ts - store-discovery-state.ts - puppeteer-preflight.ts Note: Product images from payload are still downloaded once to MinIO via image-storage.ts - this only blocks browser-rendered page images. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- backend/src/services/puppeteer-preflight.ts | 11 +++++++++++ backend/src/tasks/handlers/entry-point-discovery.ts | 12 ++++++++++++ .../src/tasks/handlers/product-discovery-http.ts | 13 +++++++++++++ backend/src/tasks/handlers/store-discovery-http.ts | 12 ++++++++++++ backend/src/tasks/handlers/store-discovery-state.ts | 11 +++++++++++ 5 files changed, 59 insertions(+) diff --git a/backend/src/services/puppeteer-preflight.ts b/backend/src/services/puppeteer-preflight.ts index 44d8b1a0..40f1008e 100644 --- a/backend/src/services/puppeteer-preflight.ts +++ b/backend/src/services/puppeteer-preflight.ts @@ -150,6 +150,17 @@ export async function runPuppeteerPreflight( const page = await browser.newPage(); + // Block unnecessary resources to save bandwidth + await page.setRequestInterception(true); + page.on('request', (request: any) => { + const resourceType = request.resourceType(); + if (['image', 'font', 'media', 'stylesheet'].includes(resourceType)) { + request.abort(); + } else { + request.continue(); + } + }); + // If proxy has auth, set it up if (proxyUrl) { const proxyUrlParsed = new URL(proxyUrl); diff --git a/backend/src/tasks/handlers/entry-point-discovery.ts b/backend/src/tasks/handlers/entry-point-discovery.ts index 05584482..f81758c0 100644 --- a/backend/src/tasks/handlers/entry-point-discovery.ts +++ b/backend/src/tasks/handlers/entry-point-discovery.ts @@ -233,6 +233,18 @@ export async function handleEntryPointDiscovery(ctx: TaskContext): Promise { + const resourceType = request.resourceType(); + if (['image', 'font', 'media', 'stylesheet'].includes(resourceType)) { + request.abort(); + } else { + request.continue(); + } + }); + // Setup proxy auth if needed if (proxyUrl) { const proxyUrlParsed = new URL(proxyUrl); diff --git a/backend/src/tasks/handlers/product-discovery-http.ts b/backend/src/tasks/handlers/product-discovery-http.ts index 6f9fa783..23e188e1 100644 --- a/backend/src/tasks/handlers/product-discovery-http.ts +++ b/backend/src/tasks/handlers/product-discovery-http.ts @@ -100,6 +100,19 @@ export async function handleProductDiscoveryHttp(ctx: TaskContext): Promise { + const resourceType = request.resourceType(); + // Block images, fonts, media, and stylesheets - we don't need them + if (['image', 'font', 'media', 'stylesheet'].includes(resourceType)) { + request.abort(); + } else { + request.continue(); + } + }); + // Setup proxy auth if needed if (proxyUrl) { const proxyUrlParsed = new URL(proxyUrl); diff --git a/backend/src/tasks/handlers/store-discovery-http.ts b/backend/src/tasks/handlers/store-discovery-http.ts index e434a7d7..22fb0343 100644 --- a/backend/src/tasks/handlers/store-discovery-http.ts +++ b/backend/src/tasks/handlers/store-discovery-http.ts @@ -112,6 +112,18 @@ export async function handleStoreDiscoveryHttp(ctx: TaskContext): Promise { + const resourceType = request.resourceType(); + if (['image', 'font', 'media', 'stylesheet'].includes(resourceType)) { + request.abort(); + } else { + request.continue(); + } + }); + // Setup proxy auth if needed if (proxyUrl) { const proxyUrlParsed = new URL(proxyUrl); diff --git a/backend/src/tasks/handlers/store-discovery-state.ts b/backend/src/tasks/handlers/store-discovery-state.ts index 294c2c9f..1fe6e4ff 100644 --- a/backend/src/tasks/handlers/store-discovery-state.ts +++ b/backend/src/tasks/handlers/store-discovery-state.ts @@ -111,6 +111,17 @@ export async function handleStoreDiscoveryState(ctx: TaskContext): Promise { + const resourceType = request.resourceType(); + if (['image', 'font', 'media', 'stylesheet'].includes(resourceType)) { + request.abort(); + } else { + request.continue(); + } + }); + // Setup proxy auth if needed if (proxyUrl) { const proxyUrlParsed = new URL(proxyUrl);