Search code examples
javascriptgoogle-chromegoogle-developer-tools

How to open multiple links on a page at once in new tabs or window from chrome's dev tool console?


Assume a website containing links:

<a href="https://www.google.com">google</a>
<a href="https://www.yahoo.com">yahoo</a>
<a href="https://www.bing.com">bing</a>

I want to open each one of them in a new tab from chrome's dev tool console.

I though I could achieve this via running the following from the console:

const as = document.querySelectorAll('a');
as.forEach(a => a.setAttribute('target', '_blank'));
as.forEach(a => a.click())

Yet it only opens the first one, then stops.

I also tried window.open:

[...document.querySelectorAll('a')].map(a => a.href).forEach(window.open)

or

[...document.querySelectorAll('a')].map(a => a.href).forEach(href => window.open(href, '_blank'));

This too only opens the first link, not the others.

How do I open all links in a new tab or window from chrome's dev console?


Solution

  • You need to explicitly give permissions for every site you want to open multiple filesChrome Browser Pop-ups blocked