JS-throttling in background tabs; bug or feature?

  • Hey guys. I've recently updated to the latest Vivaldi Snapshot 1.5.638.3 which comes with a new Chromium engine. Ever since this change, the browser is behaving differently. Some testing has revealed that [b]any and all JavaScript code[/b] in a background tab is reduced to being executed once every 2 seconds. This is, at least to me, a serious issue because I need some more accurate timing than this for a small number of custom scripts which I'm running on webpages via Tampermonkey. Since the userscript code is injected into the webpage, any tab throttling applies to that code as well. Before the update, the setTimeout/setInterval calls were throttled to once per second I believe and could be circumvented with WebWorkers to be executed at the desired moment or interval. After updating to the latest Vivaldi Snapshot, this does not work any more. I haven't diagnosed why that is exactly, but I would love some information if this is to be considered a bug or an expected behavior that's being pushed on users with the new Chromium base. Regards, flash

  • Chromium-based browsers + Firefox (idk about other Gecko-based) do this since 2012. IIRC Internet Explorer does it too. Same for Edge.

    You can disable it with command line option AFAIK, but you have to search for it. Also you may want to try some workarounds: https://blog.pivotal.io/labs/labs/chrome-and-firefox-throttle-settimeout-setinterval-in-inactive-tabs - I don't know if they'll work. You may try Web Workers too.

    Personally I think it's a very good feature. There isn't much use cases when this is undesierd and can't be worked around.

  • Hi jacekn and thanks for your reply.

    I already mentioned in my previous post, that the old Vivaldi throttled JS in background tabs, just like most other browsers do by default. That's not the issue, because in Firefox and Opera I can disable this feature entirely and generally speaking, any other browser I know of, was able to circumvent this throttling with the use of WebWorkers as you rightly said.

    I've been doing exactly that for a long time and so far it has worked fine in all previous versions of Vivaldi until snapshot 1.5.627.3 (it should be fine in 1.5.633.16 as well but I didn't use that version). Since the update past said snapshot however, any use of the previous circumvention code produces bad results. Take a look at the following:

    var xBlob = new Blob(["var interval; self.addEventListener('message', function(e){ switch (e.data) { case 'start': interval = setInterval(function(){ self.postMessage('tick'); }, 100); break; case 'stop': clearInterval(interval); break; }; }, false);"], {type: "application/javascript"});
    var prev;
    var worker = new Worker(URL.createObjectURL(xBlob));
    worker.addEventListener("message", function(e) {
    	var now = new Date();
    	console.log(e.data, now-prev);
    	prev = now;
    function test() {

    If the page is in the foreground everything is fine and the console is quickly filled with almost identical "tick 100" entries, the odd "tick 99" and "tick 101" in between. However, as soon as I switch to another tab, the behavior becomes very strange. The new console output is "tick 999 tick 0 tick 0 tick 0 tick 0 tick 1 tick 0 tick 0 tick 0 tick 0" within one second. Normally, since this setInterval() is called from within a WebWorker, it should not be affected by throttling at all. That's how the whole thing worked for years!

    While the code is still executed ten times per second, it's not possible any more to spread this execution out equally over time, instead all of the calls now run in a series without any break in between. This change out-right breaks some features I wrote userscripts for and I would assume a host of other websites' features too. One of those I wrote for myself is a fade-out fade-in for media playback, where I would adjust the volume every x milliseconds to achieve the desired effect.

    In order to get around this issue, I tried using the "–disable-background-timer-throttling" flag. It is mentioned as being applied in the vivaldi://about page, but it has no effect on this issue.

    I just tested the above code on a portable version of the Chromium 56 browser and it behaves the same way as the latest Vivaldi snapshot does, breaking my desired functionality. At least it's not a Vivaldi only issue, although by using the Blink engine, the Vivaldi devs do import both bugs and features into their Browser and this is one of them. I guess knowing the kind of developers of Chrome/Chromium, this is yet another "feature" we receive without an ability to disable. Well, I'm adding this to the long list of reasons why I do not use Chrome and hope the Vivaldi devs will pick up my feature request about an option to disable background throttling entirely.


    P.S.: Yes I agree with you, this is in general a good feature. Throttling of scripts in tabs out of focus will reduce the power requirements, since the CPU will undergo less wake-up cycles. That being said, it also negatively impacts userscripts since they are nothing more than JavaScript injected into the tab's webpage. In the same vein, it's going to disrupt extension-webpage communication as well, since that too works by injecting JS code into the webpage and then communicating via messages.

Log in to reply

Looks like your connection to Vivaldi Forum was lost, please wait while we try to reconnect.