Skip to content

Commit 86491b9

Browse files
committed
采用随机间隔
1 parent efda557 commit 86491b9

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/pkg/utils/wakeup-ping.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const PING_INTERVAL_MS = 14_225;
1+
const PING_INTERVAL_MS_1 = 13_225;
2+
const PING_INTERVAL_MS_2 = 17_765;
23

34
/**
45
* scheduler 用于后台排程:Chrome 94+, Firefox 142+
@@ -34,10 +35,11 @@ export const startRepetitivePing = () => {
3435
const mutationObserver = new MutationObserver(() => {
3536
if (isMutationPending) {
3637
isMutationPending = false;
38+
const pingIntervalMs = Math.random() * (PING_INTERVAL_MS_2 - PING_INTERVAL_MS_1) + PING_INTERVAL_MS_1;
3739
if (nativeScheduler) {
38-
nativeScheduler.postTask(pingTask, { priority: "background", delay: PING_INTERVAL_MS });
40+
nativeScheduler.postTask(pingTask, { priority: "background", delay: pingIntervalMs });
3941
} else {
40-
setTimeout(pingTask, PING_INTERVAL_MS);
42+
setTimeout(pingTask, pingIntervalMs);
4143
}
4244
}
4345
});

0 commit comments

Comments
 (0)