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.

  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