Currently, I use the following hardcoded approach to exclude URLs that have a response header "Content-Disposition: attachment" to prevent Puppeteer from downloading the files.
Puppeteer version: 21.7.0
Node.js version: 20.11
NPM version: 2.4.0
await page.setRequestInterception(true);
page.on("request", (interceptedRequest) => {
if (
interceptedRequest.resourceType() === "image" ||
interceptedRequest.resourceType() === "stylesheet" ||
interceptedRequest.resourceType() === "font" ||
interceptedRequest.resourceType() === "media" ||
interceptedRequest.resourceType() === "object" ||
interceptedRequest.resourceType() === "other" ||
//Hardcoded workaround to prevent automatic downloads due to Content-Disposition: attachment
interceptedRequest.url().includes("example.com/doc/") ||
interceptedRequest.url().includes("example.com/docs/")
) {
interceptedRequest.abort();
}
But there has to be an elegant approach. Through reading the docs and the internet, even the GitHub comments, it seems there is no such possibility yet, apart from an unsupported add-on coded by a random contributor that seems not to work as to a GitHub comment in there. So, I want to use swarm knowledge over here.