puppeteer: targetcreated event not firing when 1st parameter of window.open() is empty string

The targetcreated event is not firing when window.open() is called.

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: 1.5.0
  • Platform / OS version: Windows 10.0.17134
  • Node.js version: 8.11.2

What steps will reproduce the problem?

  1. const newPagePromise = new Promise(x => browser.on('targetCreated', target => x(target.page())));
  2. await page.click("#bReport"); //Makes popup
  3. const popup = await newPagePromise; //Hangs here

In the website, the button is rigged to call var report=window.open("","Schedule","menubar=0,scrollbars=1,resizable=1"); before adding content via an AJAX call.

What is the expected result? The popup should appear in a new window, with the variable pointing at the new page created by window.open()

What happens instead? The popup does appear, but the promise hangs. I have no way to validate the contents of the popup.

This may be a duplicate of #1992. I’m making a new issue to increase visibility and hopefully find a solution.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 19 (3 by maintainers)

Most upvoted comments

… so I’ve managed to force targetcreated event in browser after opening about:blank new window by running this function:

function forceTargetInitialization(browser) {
    Array.from(browser._targets.values()).forEach((t, i) => {
        if (!t._isInitialized) {
            console.log('Forcing target initialization');
            browser._targetInfoChanged({
                targetInfo: { ...t._targetInfo, url: ' ' },
            });
        }
    });
}

I needed to force some random url there just to be different than empty string ''.

Careful though, if you have uninitialised targets for a reason you might run into troubles there. And make sure you don’t need that url that is now obviously wrong.

I would give myself a thumbs down for this solution but it helped and maybe will help someone else too. At least until it’s fixed in puppeteer/dtp.

The 'targetcreated' event is spelled with all-small letters; you have a capital ‘C’.

A rule of a thumb is that all pptr literals are small-case.