I have a problem when using the puppeteer that are: I built a console app to craw data using puppeteer, but when my app is shutdown, I still see many chromium appear in Processes Task Manager. Can you help me resolve this problem please?
you should wrap the Browser creation with using block. like this:
using(var browser = new await Puppeteer.LaunchAsync())
{
// your code here...
}
Make sure that you work with browser instance and also with page instances properly. Every opened page needs to be closed(disposed) and so does browser.
Example of correct usage:
var browser = await Puppeteer.LaunchAsync(new LaunchOptions()
{
ExecutablePath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
});
var htmlPage = await browser.NewPageAsync();
await htmlPage.GoToAsync(url);
await htmlPage.PdfAsync(path, pdfOptions);
await htmlPage.CloseAsync();
await browser.CloseAsync();
In this example I launch browser instance, open one page with specified url, download its content to path with pdfOptions, close page correctly and close browser correctly. After these steps there is no chrome instance left in task manager.
If something is unclear, feel free to ask :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With