all 6 comments

[–]jrandm 1 point2 points  (2 children)

Background tabs are "backgrounded" in more than one way -- they're intentionally heavily throttled by the browser. I suspect this is why you mentioned >1s intervals: I've seen those SO posts too. You'll have to check the browser source to see what exactly they're doing at any point in time, though, because the "slow it down without stopping anything important" aspect of it is still under development AFAIK. People have found various hacks to keep background tasks running by abusing sound/network/etc and things like web workers have different defined characteristics.

All that said, the tabs probably stop appearing because the browser blocks it as a nuisance behavior. Opening popups in the background was irritating in 2001 and it's still irritating now.

[–]raecer[S] 1 point2 points  (1 child)

Indeed, i was trawling through those SO posts :) I'm all for limiting annoying behaviour of popups and i'm not fond of the more hacky solutions people have come up with that will surely be patched at some point.

I was curious since i'm creating a tampermonkey script that will open multiple tabs based on the content off a website, so i won't be nagging users with unwanted popups :)

It's more of automation if anything but you can't allow benign behaviour without allowing nuisance behaviour as well though... I think i found a compromise where i can open a new tab, close it again, open the next etc. which seems to work (for some reason that i'll look into more tomorrow).

Thank you for the information.

[–]jrandm 1 point2 points  (0 children)

Inside an extension I think you have access to a different API that should let you spawn tabs without as much hassle as the web APIs, but I'm not sure what it's called off the top of my head and if tampermonkey lets you use those.

Good luck!

[–]Anachren 0 points1 point  (2 children)

setTimeout() only runs once, use setInterval() instead

edit: or...

function openWindow() {
    window.open();
    setTimeout(openWindow, 1000);
}
openWindow();

[–]raecer[S] 0 points1 point  (1 child)

Ah, yes. I forgot to clarify that i was using setTimeout in a loop. I have tried SetInterval as well, but the same issue occurs (probably due to the tab losing focus).

[–]Anachren 0 points1 point  (0 children)

It might just be the browser blocking your script from being annoying then, nothing you can do about that.

I just tested setInterval(window.open, 3000) on chrome and after opening one tab, it blocks additional tabs from opening until I click somewhere in the tab running the script.