Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Puppeteer-Sharp still appear many chromium instance in Process Task Manager when console app is shutdown

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?

enter image description here

like image 977
uypc Avatar asked Dec 23 '22 02:12

uypc


2 Answers

you should wrap the Browser creation with using block. like this:

using(var browser = new await Puppeteer.LaunchAsync())
{
     // your code here...
}
like image 51
Meir Blachman Avatar answered May 09 '23 04:05

Meir Blachman


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 :)

like image 33
Ciki Avatar answered May 09 '23 03:05

Ciki