Skip to content

Commit

Permalink
windowPerformance: fixes #192
Browse files Browse the repository at this point in the history
  • Loading branch information
macbre committed Jan 19, 2014
1 parent 9b9077a commit c4babd3
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions modules/windowPerformance/windowPerformance.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,31 @@ exports.module = function(phantomas) {
phantomas.setMetric('timeFrontend');

// measure onDOMReadyTime and windowOnLoadTime from the moment HTML response was fully received
phantomas.once('responseEnd', function() {
var responseEndTime = Date.now();
var responseEndTime = Date.now();

phantomas.on('responseEnd', function() {
responseEndTime = Date.now();
phantomas.log('Performance timing: responseEnd');

// extend window.performance
phantomas.evaluate(function(responseEndTime) {
window.performance = window.performance || {timing: {}};
window.performance.timing.responseEnd = responseEndTime;
}, responseEndTime);
});

phantomas.on('init', function() {
phantomas.evaluate(function() {
phantomas.evaluate(function(responseEndTime) {
(function(phantomas) {
phantomas.spyEnabled(false, 'installing window.performance metrics');

// extend window.performance
// "init" event is sometimes fired twice, pass a value set by "responseEnd" event handler (fixes #192)
window.performance = window.performance || {
timing: {
responseEnd: responseEndTime
}
};

// emulate Navigation Timing
document.addEventListener('readystatechange', function() {
var readyState = document.readyState,
Expand Down Expand Up @@ -71,7 +80,7 @@ exports.module = function(phantomas) {

phantomas.spyEnabled(true);
})(window.__phantomas);
});
}, responseEndTime);
});

// fallback for --disable-js mode
Expand Down

0 comments on commit c4babd3

Please sign in to comment.