关于setInteval定时器在不同浏览器下表现差异

背景:

项目下用到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

相关推荐
serve the people8 小时前
HTML Document Loaders in LangChain
chrome·langchain·html
凄戚1 天前
bash和命令
开发语言·chrome·bash
Evan芙1 天前
Bash 变量命名规则与类型使用
linux·运维·开发语言·chrome·bash
wyjcxyyy2 天前
polar靶场-MISC,WEB(中等)
前端·chrome
女生寝室0382 天前
《Chrome》 [142.0.7444.60][绿色便携版] 下载
前端·chrome
CS_浮鱼2 天前
【Linux】基础IO
linux·运维·chrome
Keely402852 天前
学习编写chrome插件:Hello World 扩展
前端·chrome
saber_andlibert2 天前
【Linux】Shell脚本
运维·chrome·vscode·编辑器·vim·shell
花果山总钻风2 天前
Chrome 插件框架 Plasmo 基本使用示例
前端·chrome
资讯第一线2 天前
《Chrome》 [142.0.7444.60][绿色便携版] 下载
前端·chrome