jsicon

js: window.performance on mobile

I’d been playing around with some graphically intensive tests in javascript and openGL, but when I went to test them on various mobile devices, huge aspects of them were failing. After a few minutes I realized that window.performance.now was missing. Here’s a shim I found that does the trick.

(function(){
  if ("performance" in window == false) {
      window.performance = {};
  }
  Date.now = (Date.now || function () {
    return new Date().getTime();
  });
  if ("now" in window.performance == false){
    var nowOffset = Date.now();
    if (performance.timing && performance.timing.navigationStart){
      nowOffset = performance.timing.navigationStart
    }
    window.performance.now = function now(){
      return Date.now() - nowOffset;
    }
  }
})();

the above polyfill is // copyright Paul Irish 2015

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>