browser.idle.setDetectionInterval 的范围如何?
How is browser.idle.setDetectionInterval scoped?
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": "",
"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": "",
"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}`);
});
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": "",
"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": "",
"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}`);
});