title: setTimeout/setInterval 1000ms lag in background tabs (Chrome and Firefox)
body: <p>When events are queued with setTimeout/setInterval, and the user is viewing a separate tab, Chrome and Firefox enforce a minimum 1000ms lag before the event is executed. <a href="http://pivotallabs.com/chrome-and-firefox-throttle-settimeout-setinterval-in-inactive-tabs/" rel="noreferrer">This article</a> details the behaviour.</p>
  
  <p>This has been discussed on StackOverflow previously, but the questions and answers only applied to animations. Obviously, an animation can just be forced to update to the latest state when a user re-enters the tab.</p>
  
  <p>But the solution does not work for sequenced audio. I have Web Audio API playing several audio files in sequence, and setTimeout is used to countdown to when the next audio file plays. If you put the tab in the background, you get an annoying 1 second gap between each pattern -- an extreme flaw in an API designed for advanced audio.</p>
  
  <p>You can witness this behaviour in various HTML5 sequencers, e.g. with <a href="http://patternsketch.com/" rel="noreferrer">PatternSketch</a> -- just by entering a pattern, playing, and going to another tab.</p>
  
  <p>So I'm in need of a workaround: a way to queue events without the 1000ms clamp. Does anyone know of a way?</p>
  
  <ul>
  <li><p>The only solution I can think of is to have window.postMessage run every single millisecond and check each time if the event is to execute. That is definitely detrimental to performance. Is this the only option?</p></li>
  <li><p>Apparently there is no event system planned for Web Audio API, so that is out of question.</p></li>
  </ul>