In Puppeteer, you can manage multiple tabs by using the browser
object to create new tabs and navigate between them. Here is an example of how you can open multiple tabs and switch between them:
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
})();
const page = await browser.newPage();
await page.goto('https://www.example.com');
const page2 = await browser.newPage();
await page2.goto('https://www.anotherexample.com');
page.bringToFront()
method:await page.bringToFront(); // Switch to the first tab
await page2.bringToFront(); // Switch to the second tab
You can also close tabs using page.close()
method:
await page.close(); // Close the first tab
By following these steps, you can effectively manage multiple tabs in Puppeteer.