javascript - browser.idle.setDetectionInterval 的范围如何?
问题描述
idle.setDetectionInterval()
将设置用于确定系统何时处于idle.onStateChanged
事件空闲状态的间隔,但这是否仅限于设置它的浏览器扩展,或者这是否会更改所有浏览器扩展的检测间隔?
如果重要的话,我特别关心 Firefox。
解决方案
空闲检测的范围是基于每个扩展的。
为了测试,我创建了两个扩展。一个分机的空闲检测设置为 15 秒,另一个设置为 45 秒。在日志中,我们看到第二个扩展的空闲事件在第一个扩展后 30 秒触发。
日志:
Thu Apr 11 2019 09:52:15 GMT+0200: 15 test: initialized
Thu Apr 11 2019 09:52:27 GMT+0200: 45 test: initialized
Thu Apr 11 2019 09:52:41 GMT+0200: 15 test: idle
Thu Apr 11 2019 09:53:11 GMT+0200: 45 test: idle
Thu Apr 11 2019 09:54:00 GMT+0200: 15 test: active
Thu Apr 11 2019 09:54:00 GMT+0200: 45 test: active
第一个扩展:
manifest.json
:
{
"manifest_version": 2,
"name": "Test WebExtension 1",
"author": "Jeremiah Lee",
"developer": {
"name": "Jeremiah Lee",
"url": "https://www.jeremiahlee.com/"
},
"version": "1.0.0",
"description": "Better documentation is needed",
"homepage_url": "https://stackoverflow.com/questions/53918121/how-is-browser-idle-setdetectioninterval-scoped",
"permissions": [
"idle"
],
"background": {
"scripts": ["background.js"]
}
}
background.js
:
console.log(`${new Date()}: 15 test: initialized`);
browser.idle.setDetectionInterval(15);
browser.idle.onStateChanged.addListener((state) => {
console.log(`${new Date()}: 15 test: ${state}`);
});
第二次扩展:
manifest.json
:
{
"manifest_version": 2,
"name": "Test WebExtension 2",
"author": "Jeremiah Lee",
"developer": {
"name": "Jeremiah Lee",
"url": "https://www.jeremiahlee.com/"
},
"version": "2.0.0",
"description": "Better documentation is needed",
"homepage_url": "https://stackoverflow.com/questions/53918121/how-is-browser-idle-setdetectioninterval-scoped",
"permissions": [
"idle"
],
"background": {
"scripts": ["background.js"]
}
}
background.js
:
console.log(`${new Date()}: 45 test: initialized`);
browser.idle.setDetectionInterval(45);
browser.idle.onStateChanged.addListener((state) => {
console.log(`${new Date()}: 45 test: ${state}`);
});
推荐阅读
- powershell - Exchange MS v2.0 导出到 CSV -append 错误
- autodesk-forge - 如何在 Forge 上获取 Revit 文件的 3D 视图
- apache-flink - 在 EMR 集群中提交 Flink 作业:初始化集群入口点 YarnJobClusterEntrypoint 失败
- regex - 正则表达式:仅在斜杠之间匹配路由参数,但可选结束斜杠
- bash - 正则表达式适用于 VS Code 搜索/替换,但不适用于 sed 脚本
- django - 在 django CBV 中复制带有表单的对象
- python - 基于相同的列值合并两个数据框
- git - 使用 git fetch --no-tags 获取 repo 后检查分支
- mysql - MySQL 更新的 Python 格式字符串
- python - 从 Python 列表中复制值会返回方括号和引号