uypc
uypc

Reputation: 81

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

Upvotes: 7

Views: 5255

Answers (3)

Hasan Kağan BAYRAM
Hasan Kağan BAYRAM

Reputation: 21

After all try to close browser method, unfourtunately you cant kill chrome processes. You need to kill chrome process by id (pid)

using var currentPage = new await Puppeteer.LaunchAsync();
var chromeProcess = Process.GetProcesses().FirstOrDefault(x => x.Id == currentPage.Browser.Process.Id);

if (chromeProcess != null) {
   chromeProcess.Kill();
}

Upvotes: 2

Ciki
Ciki

Reputation: 51

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

Upvotes: 3

Meir Blachman
Meir Blachman

Reputation: 345

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

using (var browser = new await Puppeteer.LaunchAsync())
{
    // your code here...
}

Upvotes: 9

Related Questions