Skip to content

Instantly share code, notes, and snippets.

@surfmuggle
Last active January 23, 2019 01:46
Show Gist options
  • Save surfmuggle/e43bd2b9c5a669948ffdaf6074be71cb to your computer and use it in GitHub Desktop.
Save surfmuggle/e43bd2b9c5a669948ffdaf6074be71cb to your computer and use it in GitHub Desktop.
Firefox Extension - why does it log page.renderTime -1548207097891 instead of something like = 885
document.onreadystatechange = function () {
console.log("content script was fired onreadystatechange ");
class PageMeasurement {
constructor(url) {
this.url = url;
this.date = Date.now();
var t = window.performance.timing;
this.pageLoadTime = (t.loadEventEnd - t.fetchStart);
this.renderTime = (t.loadEventEnd - t.responseEnd);
}
}
if (document.readyState === 'complete') {
console.log("document.readyState === complete")
var page = new PageMeasurement(document.URL);
console.log("page.renderTime", page.renderTime);
}
}
@surfmuggle
Copy link
Author

If i paste the class below into the console directly it returns the correct render time. As part of my extension (see above) it does not. Why is this the case?

var p = new PageMeasurement(document.URL)
p.renderTime  // results in 1656
    class PageMeasurement {
        constructor(url) {
            this.url = url;
            this.date = Date.now();
            var t = window.performance.timing; 
            this.pageLoadTime = (t.loadEventEnd - t.fetchStart);
            this.renderTime =  (t.loadEventEnd - t.responseEnd);	
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment