背景:
项目下用到websocket, 中间使用了setInterval 定时向服务端发送心跳包, 5s/次, 观察正常, 就将浏览器最小化后, 经过了两天, 周一过来查看, 咋才 5000次;
问题分析:
遇到这种简单的问题当然是请教一下GPT 来的最快最实际, 不出所料, 马上得到证实;
chrome 88 版本之后就加入了这个功能, 当标签页处于非活动状态时, 定时器的循环时间会被节流, 设置为 1分钟每次;
https://developer.chrome.com/blog/timer-throttling-in-chrome-88/

解决办法:
在启动命令后增加 --disable-background-timer-throttling 参数
例如: chrome.exe --disable-background-timer-throttling
