1. // rAF never fires on devtools_page (because it's in the background)
    
  2. // https://bugs.chromium.org/p/chromium/issues/detail?id=1241986#c31
    
  3. // Since we render React elements here, we need to polyfill it with setTimeout
    
  4. // The polyfill is based on https://gist.github.com/jalbam/5fe05443270fa6d8136238ec72accbc0
    
  5. const FRAME_TIME = 16;
    
  6. let lastTime = 0;
    
  7. 
    
  8. window.requestAnimationFrame = function (callback, element) {
    
  9.   const now = window.performance.now();
    
  10.   const nextTime = Math.max(lastTime + FRAME_TIME, now);
    
  11. 
    
  12.   return setTimeout(function () {
    
  13.     callback((lastTime = nextTime));
    
  14.   }, nextTime - now);
    
  15. };
    
  16. 
    
  17. window.cancelAnimationFrame = clearTimeout;