On all sites when I run this script using tamperMonkey

// ==UserScript== // @name My Fancy New Userscript2 // @namespace http://your.homepage/ // @version 0.1 // @description enter something useful // @author You // @match https://www.google.com/ // @grant GM_xmlhttpRequest // ==/UserScript== var timer = 0; function test() { console.log(timer); timer = setTimeout(test, 5000); } test(); 

then I see in the console:

 0 16 42 73 98 110 ... 251 252 253 

At the beginning of the big ID jumps, and then the rules, why tell me so? on locale machine all the rules ...

    1 answer 1

    TamplerMonkey also uses setTimeout .
    setTimeout increases the global ID counter regardless of where it was called from.
    setInterval also increments the ID counter.

     var timer = 0; function test() { ++timer; console.log(timer); setTimeout(test, 5000); } test(); // Увеличиваем счетчик id for(var i = 0; i < 10; i++){ setTimeout(function(){}, 100); } 
    • Damilon tell me how to solve the problem? - bsbak pm
    • Updated the answer, note that the timer needs to be increased in all functions where you call setTimeout; - Robert Dampilon pm