退出 Firefox 时警报是否仍然存在?

Do alarms persist when quitting Firefox?

如果 Firefox 附加扩展使用 browser.alarms.create 设置了警报,然后用户退出 Firefox,下次打开 Firefox 时警报是否仍然存在?

如果是这样,如果超过延迟,是否会立即触发使用 delayInMinutes 创建的警报?

如果是这样,使用 periodInMinutes 创建的警报是否会根据浏览器退出前的初始触发时间或浏览器打开时间继续触发?

警报不会跨浏览器会话持续存在。

下面的代码在签名和安装时(临时加载的扩展在浏览器退出时卸载)将输出:

Extension running. Current alarms:
Array []
background.js:4:13
2019-03-16T17:15:10.841Z: Alarm should go off every minute. background.js:13:13
2019-03-16T17:16:10.912Z: test-alarm-1 background.js:16:17
2019-03-16T17:17:10.919Z: test-alarm-1 background.js:16:17
2019-03-16T17:18:10.922Z: test-alarm-1 background.js:16:17

​// Restart Firefox, reopen debugging.

Extension running. Current alarms: 
Array []
background.js:4:13
2019-03-16T17:18:40.689Z: Alarm should go off every minute. background.js:13:13
2019-03-16T17:19:40.796Z: test-alarm-1 background.js:16:17

如果警报持续存在,数组将有 1 个项目。

manifest.json:

{
    "manifest_version": 2,
    "name": "Test WebExtension",
    "author": "Jeremiah Lee",
    "developer": {
        "name": "Jeremiah Lee",
        "url": "https://www.jeremiahlee.com/"
    },
    "version": "0.1.0",
    "description": "Better documentation is needed",
    "homepage_url": "",
    "permissions": [
        "<all_urls>",
        "alarms",
        "tabs"
    ],
    "background": {
        "page": "./lib/background.html"
    }
}

background.html:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script type="module" src="./background.js"></script>
</head>
</html>

background.js:

(async function() {
    const alarms = await browser.alarms.getAll();

    console.log(`Extension running. Current alarms:`, alarms);

    await browser.alarms.create(
        "test-alarm-1",
        {
            periodInMinutes: 1
        }
    );

    console.log(`${new Date().toISOString()}: Alarm should go off every minute.`);

    function handleAlarm(alarmInfo) {
        console.log(`${new Date().toISOString()}: ${alarmInfo.name}`);
    }

    browser.alarms.onAlarm.addListener(handleAlarm)
})();