导航计时 API 事件未按顺序触发

编程入门 行业动态 更新时间:2024-10-26 07:33:59
本文介绍了导航计时 API 事件未按顺序触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在使用 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 09:46:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1392013.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:顺序   未按   事件   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!