gpt4 book ai didi

javascript - 窗口性能不起作用

转载 作者:行者123 更新时间:2023-12-03 05:07:44 24 4
gpt4 key购买 nike

 var navigationStartTime                = window.performance.timing.navigationStart;

function domTimingRecordEvents(){
var domEventObject = {};
var domArray = [];

domEventObject.domLoadingStartTime = (window.performance.timing.domLoading - navigationStartTime)/1000;
domEventObject.domInteractiveTime = (window.performance.timing.domInteractive - navigationStartTime)/1000;
domEventObject.domContentLoadedEventStartTime = (window.performance.timing.domContentLoadedEventStart - navigationStartTime)/1000;
domEventObject.domContentLoadedEventEndTime = (window.performance.timing.domContentLoadedEventEnd - navigationStartTime)/1000;
domEventObject.domCompleteTime = (window.performance.timing.domComplete - navigationStartTime)/1000;
domEventObject.loadEventStartTime = (window.performance.timing.loadEventStart - navigationStartTime)/1000;
//var loadEventEndTime = (window.performance.timing.loadEventEnd - navigationStartTime)/1000;

domArray.push(domEventObject);
console.table(domArray);
}

domTimingRecordEvents();

  1. 上面的代码在 Chrome 和 Firefox 中运行顺利,但在 Opera 浏览器中运行时出现错误。
  2. 我检查了 Opera 窗口中的控制台返回窗口,但 window.performance 返回未定义
  3. 在上面的代码中,我在 JavaScript 中计算各种页面事件后得到了以秒为单位的时间。
  4. 我应该使用:-

.

 var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;

并跳过上面的代码或者有其他方法吗?

最佳答案

Windows 性能是 JavaScript 中的新事物,并且所有浏览器尚不支持所有功能。

请查看 Mozilla 的文档,了解每个浏览器实现了哪些功能

https://developer.mozilla.org/en-US/docs/Web/API/Performance

关于javascript - 窗口性能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41953762/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com