alarms

在未来一个特定的时间运行的计划任务代码。这很像setTimeout()setInterval(),不过这些函数仅可以按需使用而不能在后台页面工作。

想要使用这个API,您需要获取"alarms"的permission

类型

alarms.Alarm
Information about a particular alarm.

方法

alarms.create()
创建新的alarm.
alarms.get()
通过名称获取指定的alarm.
alarms.getAll()
获取所有的alarm.
alarms.clear()
清除指定名称的alarm.
alarms.clearAll()
清除所有的alarm.

事件

alarms.onAlarm
当alarm发生的时候触发.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxOperaFirefox for Android
AlarmChrome Full support YesEdge No support NoFirefox Full support 45Opera Full support YesFirefox Android Full support 48
clearChrome Full support YesEdge No support NoFirefox Full support 45Opera Full support YesFirefox Android Full support 48
clearAllChrome Full support YesEdge No support NoFirefox Full support 45Opera Full support YesFirefox Android Full support 48
createChrome Full support YesEdge No support NoFirefox Full support 45
Full support 45
No support 45 — 64
Notes
Notes Alarms scheduled for a time in the past never fire.
Opera Full support YesFirefox Android Full support 48
Full support 48
No support 48 — 64
Notes
Notes Alarms scheduled for a time in the past never fire.
getChrome Full support YesEdge No support NoFirefox Full support 45Opera Full support YesFirefox Android Full support 48
getAllChrome Full support YesEdge No support NoFirefox Full support 45Opera Full support YesFirefox Android Full support 48
onAlarmChrome Full support YesEdge No support NoFirefox Full support 45Opera Full support YesFirefox Android Full support 48

Legend

Full support  
Full support
No support  
No support
See implementation notes.
See implementation notes.

 

Example extensions

Acknowledgements

This API is based on Chromium's chrome.alarms API.

Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.