Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Puppeteer nodejs close page

Is there a way to close a tab in puppeteer? Or do tabs automatically close when there is no reference to it (i.e., similar to garbage collector)?

My code's structure:

//main
let browser = await puppeteer.launch()
let res1 = await func1(browser);
let res2 = await func1(browser);

function func1(browser) {
    browser.newPage();
    ...
    //I'm not closing the page
}

1 Answers

There's a way to close a page:

page.close();

You can read about details in the docs for the API: https://github.com/puppeteer/puppeteer/blob/main/docs/api/puppeteer.page.close.md

was https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#pagecloseoptions

like image 157
pavelsaman Avatar answered Sep 05 '25 13:09

pavelsaman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!