Skip to content

Commit 37845f9

Browse files
committed
feat: Stop downloading video/audio in playwright
1 parent 9eecda1 commit 37845f9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

apps/workers/workers/crawlerWorker.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,25 @@ async function crawlPage(
452452
await globalBlocker.enableBlockingInPage(page);
453453
}
454454

455+
// Block audio/video resources
456+
await page.route("**/*", (route) => {
457+
const request = route.request();
458+
const resourceType = request.resourceType();
459+
460+
// Block audio/video resources
461+
if (
462+
resourceType === "media" ||
463+
request.headers()["content-type"]?.includes("video/") ||
464+
request.headers()["content-type"]?.includes("audio/")
465+
) {
466+
route.abort();
467+
return;
468+
}
469+
470+
// Continue with other requests
471+
route.continue();
472+
});
473+
455474
// Navigate to the target URL
456475
logger.info(`[Crawler][${jobId}] Navigating to "${url}"`);
457476
const response = await Promise.race([

0 commit comments

Comments
 (0)