我正在使用Navigation Timing API从页面获取加载事件。我在下面添加了JS片段来输出信息。有一件事我注意到奇怪的是loadEventEnd
时间早于检查控制台的loadEventStart
时间。我认为这不应该是可能的。
var startTime = new Date().getTime();
// retrieve the performance object in a cross browser way. Check window.performance first.
window.performance = window.performance || window.mozPerformance || window.msPerformance || window.webkitPerformance || {};
var timing = window.performance.timing || {};
var navigation = window.performance.navigation || {};
// if the Navigation Timing API is supported
if (window.performance && window.performance.timing) {
pageRequestStart = timing.requestStart;
pageResponseStart = timing.responseStart;
pageResponseEnd = timing.responseEnd;
pageLoadEventStart = timing.loadEventStart;
pageLoadEventEnd = timing.loadEventEnd;
pageLoadTime = timing.navigationStart;
}
var timingOutput =
"requestStart: " + pageRequestStart + "\n"
+ "responseStart: " + pageResponseStart + "\n"
+ "responseEnd: " + pageResponseEnd + "\n"
+ "loadEventStart: " + pageLoadEventStart + "\n"
+ "loadEventEnd: " + pageLoadEventEnd + "\n"
+ "navigationStart: " + pageLoadTime;
console.log(timingOutput);
答案 0 :(得分:1)
虽然我不确定您的具体情况,但NavigationTiming APIs对于IE,Chrome,Firefox和Opera来说都是相当新的。在浏览器的规范和实现的开发过程中,由于浏览器之间的各种实现差异,许多小错误被看作与上面描述的类似。
您看到的错误可能已在最近的浏览器版本中得到修复。如果您仍然在正在运行的浏览器上看到问题,则可以尝试使用W3C webperf test cases for NavigationTiming查看是否有任何内容失败。