user14833861
user14833861

Reputation:

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
}

Upvotes: 4

Views: 8262

Answers (2)

pavelsaman
pavelsaman

Reputation: 8322

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

Upvotes: 14

Nick
Nick

Reputation: 31

await page.close(); 

Close function is asynchronous. That's why if you run multiple instances of Puppeteer, you should add await

Upvotes: 3

Related Questions