Question: how to handle the popup and access the popup to do some operations on it. 

```
const puppeteer = require('puppeteer');

async function run() {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    await page.goto('https://example.com');
    await page.click(Launchpopup);
}

```

Answer: 
Since version 0.13.0, you can use the following code:

```
... code to open popup...
const pages = await browser.pages(); // get all open pages by the browser
const popup = pages[pages.length - 1]; // the popup should be the last page opened

```
Puppeteer popup event

Starting with puppeteer version 1.12, a special ‘popup’ event has been added to the page, which allows you to catch new tabs and popups. We use it by rewriting the first example:

```
const puppeteer = require('puppeteer');         // puppeteer

const browser = await puppeteer.launch();       // run browser
const page = await browser.newPage();           // open new tab
await page.goto('https://example.com');            // go to site.com       

await page.waitForSelector('#goto');            // wait object load
const link = await page.$('#goto');             // declare object

const newPagePromise = new Promise(x => page.once('popup', x));

await link.click();                        // click, a new tab  opens
const newPage = await newPagePromise; 
await newPage.close();             // close it, for example
await browser.close();                          // close browser

```