Search code examples
c#puppeteerpuppeteer-sharp

Disabling Extensions in PuppeteerSharp


I need to disable all extensions within the chrome browser using Puppeteer. I used the --disable-extensions argument like below.

var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
   Headless = true,
   ExecutablePath = ChromePath,
   IgnoreHTTPSErrors = true,
   Args = new[] { "--disable-extensions" },
});

When I try to load a file URL (for example https://winaero.com/downloads/Win7Games4Win10_8_81_v2.zip), the Internet Download Manager will pop up to start the download. I'm using the headless mode to hide everything and I have used --disable-extensions to disable any extension like Internet Download Manager. Why is it not working? where is the problem?


Solution

  • Not sure you can disable the built in download manager with --disable-extensions.

    Another approach if it is just ZIP's you want to stop is to plumb this code in:-

    await page.setRequestInterception(true);
    page.on('request', request => {
        if (request.url().endsWith('.zip'))
            request.abort();
        else
          request.continue();
    });
    

    You may also want to lower case the url so you also trap .ZIP abnd Zip etc

    Also on your goto you will need to abort the request e.g.

      await page
            .goto("https://winaero.com/downloads/Win7Games4Win10_8_81_v2.zip")
            .catch(r => r.abort);