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?
Asked
Active
Viewed 4,043 times
6
-
How is your app being shutdown? – hardkoded Nov 19 '18 at 13:28
-
1F5 and Shift F5 for shutdown @hardkoded, maybe that caused problem – uypc Oct 21 '19 at 09:43
3 Answers
9
you should wrap the Browser creation with using block. like this:
using(var browser = new await Puppeteer.LaunchAsync())
{
// your code here...
}

Meir Blachman
- 325
- 2
- 6
3
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 :)

Ciki
- 51
- 2
-
2Prefer wrapping the browser and page creation with *using* blocks. This will ensure properly disposal of the objects which, in fact, will call *CloseAsync()* internally. – dvlsc Feb 28 '19 at 11:20
0
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();