导航计时 API 事件未按顺序触发 [英] Navigation Timing API events not firing in order

查看:35
本文介绍了导航计时 API 事件未按顺序触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Navigation Timing API 从页面获取加载事件.我在下面添加了 JS 的片段来输出信息.我注意到的一件事很奇怪,当我检查控制台时,loadEventEnd 时间比 loadEventStart 时间回来得早.我认为这不应该.

I'm using the Navigation Timing API to get load events from a page. I've added the snippet of JS below to output the information. One thing I noticed that was strange was that the loadEventEnd time came back sooner than the loadEventStart time when I check the console. I would think that shouldn't be possible.

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);

推荐答案

虽然我不确定您的案例的具体情况,NavigationTiming API 对 IE、Chrome、Firefox 和 Opera 来说是相当新的.在开发规范和浏览器实现的过程中,由于浏览器之间的各种实现差异,发现了许多类似于您上面描述的小错误.

While I'm not sure of the specifics of your case, the NavigationTiming APIs are fairly new to IE, Chrome, Firefox and Opera. During development of the specification and implementation in the browsers, many small bugs were seen similar to what you describe above due to various implementation differences between the browsers.

您看到的错误很可能已在最近的浏览器版本中得到修复.如果您在运行的浏览器上仍然看到该问题,您可以尝试 W3C webperf 测试NavigationTiming 的案例,以查看是否有任何失败.

It's likely the bug you saw has been fixed in recent browser versions. If you're still seeing the issue consistently on a browser you're running, you can try the W3C webperf test cases for NavigationTiming to see if anything fails.

这篇关于导航计时 API 事件未按顺序触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆