Cancel Downloading in PuppeteerSharp

Viewed 301

I need to check if the file size is more than a given size, cancels the download.

Here is my LaunchOptions:

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

and here which I have done more:

await page.Client.SendAsync("Page.setDownloadBehavior", new
{
    behavior = "allow",
    downloadPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
});

await page.SetRequestInterceptionAsync(true);

page.Request += (s, er) =>
{
    if (er.Request.Headers.ContainsKey("Content-Length") && Convert.ToInt64(er.Request.Headers["Content-Length"]) > GIVENSIZE)
    {
        er.Request.AbortAsync();
        return;
    }
}

There are two problems, the --disable-extensions won't work, the internet download manager will pop up to download the file, and the Request does not contain a Content-Length header to let me check for file size.

Any Idea?

1 Answers
Related