3

Here are my starting settings (It is NOT headless and you can see the browser opening while navigating)

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

and here are some codes before navigation:

var pages = await browser.PagesAsync();
var page = pages[0];

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

and then navigating to a file URL (like: https://codeload.github.com/stenzek/duckstation/zip/master)

await page.GoToAsync(url, WaitUntilNavigation.Networkidle2);

The browser will open and it starts downloading the file. I have a timer and I need to stop downloading after 5 seconds. I used this code to stop the page loading:

await page.Client.SendAsync("Page.stopLoading");

It will close the whole browser and the file will delete. I only need to stop downloading the file. How to achieve such a thing?

Inside Man
  • 4,194
  • 12
  • 59
  • 119
  • `I have a timer and I need to stop downloading after 5 seconds.` Why? – mjwills Jan 13 '21 at 12:42
  • @mjwills for example the file size is so huge or the file size can not be retrieved, so I need to download some bytes of the file and then process the response. – Inside Man Jan 13 '21 at 12:49
  • Have you tried to access the partially downloaded file while downloading, make your own considerations, and only after to close your browser? – AndreaTaroni86 Jan 25 '21 at 17:31

0 Answers0