Puppeteer: How to handle multiple tabs?

后端 未结 8 822
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-13 09:09

Scenario: Web form for developer app registration with two part workflow.

Page 1: Fill out developer app details and click on button to create Application ID, which

8条回答
  •  借酒劲吻你
    2020-12-13 09:52

    it looks like there's a simple 'page.popup' event

    Page corresponding to "popup" window Emitted when the page opens a new tab or window.

    const [popup] = await Promise.all([
      new Promise(resolve => page.once('popup', resolve)),
      page.click('a[target=_blank]'),
    ]);
    const [popup] = await Promise.all([
      new Promise(resolve => page.once('popup', resolve)),
      page.evaluate(() => window.open('https://example.com')),
    ]);
    

    credit to this github issue for easier 'targetcreated'

提交回复
热议问题