Skip to content

Commit 0b99453

Browse files
committed
fix: timeline duplicated (#662)
1 parent b5011f5 commit 0b99453

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
"@emotion/babel-plugin": "^11.13.5",
3333
"@emotion/css": "^11.13.5",
3434
"@rsdoctor/rspack-plugin": "^1.4.0",
35-
"@rspack/cli": "^1.6.8",
36-
"@rspack/core": "^1.6.8",
37-
"@swc/core": "^1.15.7",
35+
"@rspack/cli": "^1.7.1",
36+
"@rspack/core": "^1.7.1",
37+
"@swc/core": "^1.15.8",
3838
"@swc/jest": "^0.2.39",
3939
"@types/chrome": "0.1.32",
4040
"@types/decompress": "^4.2.7",
@@ -43,7 +43,7 @@
4343
"@types/punycode": "^2.1.4",
4444
"@vue/babel-plugin-jsx": "^2.0.1",
4545
"babel-loader": "^10.0.0",
46-
"commitlint": "^20.2.0",
46+
"commitlint": "^20.3.1",
4747
"css-loader": "^7.1.2",
4848
"decompress": "^4.2.1",
4949
"husky": "^9.1.7",
@@ -63,7 +63,7 @@
6363
"dependencies": {
6464
"@element-plus/icons-vue": "^2.3.2",
6565
"echarts": "^6.0.0",
66-
"element-plus": "2.13.0",
66+
"element-plus": "2.13.1",
6767
"punycode": "^2.3.1",
6868
"vue": "^3.5.26",
6969
"vue-router": "^4.6.4"

src/content-script/timeline.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,32 @@ class TimelineCollector {
77
* Bind page visibility and focus events
88
*/
99
init(): void {
10-
document.addEventListener('visibilitychange', () => {
11-
if (document.hidden) {
12-
this.collect()
13-
} else {
10+
const onStateChange = () => {
11+
if (!document.hidden && document.hasFocus()) {
1412
this.startTracking()
13+
} else {
14+
this.collect()
1515
}
16-
})
16+
}
1717

18-
window.addEventListener('focus', () => this.startTracking())
19-
window.addEventListener('blur', () => this.collect())
18+
document.addEventListener('visibilitychange', onStateChange)
19+
window.addEventListener('focus', onStateChange)
20+
window.addEventListener('blur', onStateChange)
2021
window.addEventListener('beforeunload', () => this.collect())
2122

2223
if (document.readyState === 'complete') {
23-
this.startTracking()
24+
onStateChange()
2425
} else {
25-
window.addEventListener('load', () => this.startTracking())
26+
window.addEventListener('load', onStateChange)
2627
}
2728
}
2829

2930
/**
3031
* Start tracking current page
3132
*/
3233
public startTracking(): void {
34+
if (document.hidden || !document.hasFocus()) return
35+
if (this.startTime !== null) return
3336
this.startTime = Date.now()
3437
}
3538

0 commit comments

Comments
 (0)