question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
epicfooxcommented, Jul 23, 2020

… 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.

1reaction
aslushnikovcommented, Jun 29, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Window.open() - Web APIs - MDN Web Docs
A string indicating the URL or path of the resource to be loaded. If an empty string ( "" ) is specified or...
Read more >
Puppeteer documentation - DevDocs
event : 'targetcreated'. <Target>. Emitted when a new target is created inside the browser context, for example when a new page is opened...
Read more >
Target domain - Chrome DevTools Protocol - GitHub Pages
Creates a new page. parameters. url: string. The initial URL the page will be navigated to. An empty string indicates about:blank ...
Read more >
sending custom parameters with window.open() but its not ...
But its not working as I want. I have tried the following ways 1. window.open("http://localhost:8080/login ...
Read more >
How to set User-Agent header with Puppeteer JS and not fail
Firefox, Internet Explorer, Edge … gives empty string; oscpu: only Firefox ... Website can check if we are messing around with window.open() function....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found