4

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?

Inside Man
  • 4,194
  • 12
  • 59
  • 119
  • Maybe you can somehow get the checksum by doing some low-level things involving TCP packages then find the size likewise. – DudeManGuy Dec 28 '20 at 12:22

1 Answers1

0

Try adding the URL/Domain to Internet Download Manager's exception list. It will ignore the download request.

Vikram Kumar
  • 3,876
  • 1
  • 17
  • 28
  • Internet download manager just was an example, if I disable it then the chrome itself will download the file. I need to cancel downloading by checking the file size. – Inside Man Dec 28 '20 at 13:15