2

I'm having trouble opening new windows programmatically in Google Chrome (version 62.0.3202.94).

Go give this a try:

function test(){
    console.log("haha");
}
setInterval(test, 1000);

... and you'll see a new line of haha every second.

When you try this:

function test(){
    window.open("https://stackoverflow.com/");
}
setInterval(test, 1000);

... you won't see a new page of Stack Overflow opening every second.

However, typing window.open("https://stackoverflow.com/") into the developer console and hitting enter does open a new page of Stack Overflow.

This is quite annoying because I'm going to automate something. Is there a workaround?

iBug
  • 35,554
  • 7
  • 89
  • 134

1 Answers1

0

When you execute javscript in the developer console, chrome consider that the code is executing from the website, and it blocks intrusive popups.

So for example, when i execute following code :

[0, 1, 2, 3].forEach(x => window.open("http://www.google.com", "_blank"))

I get following warning in url bar : enter image description here

You must explicitly allow chrome to display popups from the page you are executing your code from

Camille Vienot
  • 727
  • 8
  • 6