Skip to content

Commit

Permalink
fix: 修正 loadTime 的计算
Browse files Browse the repository at this point in the history
  • Loading branch information
strick committed Jan 19, 2023
1 parent 0736728 commit 5281d3f
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/lib/performance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: strick
* @LastEditors: strick
* @Date: 2023-01-12 18:18:45
* @LastEditTime: 2023-01-18 18:33:48
* @LastEditTime: 2023-01-19 09:51:54
* @Description: 性能监控
* @FilePath: /web/shin-monitor/src/lib/performance.ts
*/
Expand Down Expand Up @@ -353,18 +353,21 @@ class PerformanceMonitor {
* 注册 laod 和页面隐藏事件
*/
public registerLoadAndHideEvent(): void {
const send = (): void => {
const data = this.getTimes();
if(this.isNeedHideEvent && data) {
this.http.sendPerformance(data);
this.isNeedHideEvent = false;
}
};
/**
* 在 load 事件中,上报性能参数
* 该事件不可取消,也不会冒泡
*/
window.addEventListener('load', (): void => {
const data = this.getTimes();
// 加定时器是避免在上报性能参数时,loadEventEnd 为 0,因为事件还没执行完毕
setTimeout((): void => {
if(data) {
this.http.sendPerformance(data);
this.isNeedHideEvent = false;
}
send();
}, 0);
});
/**
Expand All @@ -374,11 +377,7 @@ class PerformanceMonitor {
const isIOS = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
const eventName = isIOS ? 'pagehide' : 'beforeunload';
window.addEventListener(eventName, (): void => {
const data = this.getTimes();
if(this.isNeedHideEvent && data) {
this.http.sendPerformance(data);
this.isNeedHideEvent = false;
}
send();
}, false);
}
}
Expand Down

0 comments on commit 5281d3f

Please sign in to comment.