browser.idle.setDetectionInterval如何作用域?

问题描述 投票:1回答:1

idle.setDetectionInterval()将设置用于确定系统何时处于idle.onStateChanged事件的空闲状态的时间间隔,但是它是否设置为设置它的浏览器扩展,还是更改了所有浏览器扩展的检测间隔?

如果重要的话,我特别关心Firefox。

javascript firefox-addon firefox-webextensions
1个回答
0
投票

空闲检测的范围基于每个扩展。

为了测试,我创建了两个扩展。一个分机的空闲检测设置为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}`);
});
© www.soinside.com 2019 - 2024. All rights reserved.