Chapter 6. Miscellaneous APIs

This chapter discusses a grab-bag of Chrome APIs, none of which warrants a full chapter of its own. Some of them are pretty useful, and others you’ll want to read about but will probably never use.


JavaScript has always had a way to set one-time or periodic alarms by using the setInterval and setTimeout functions, but their lifetime was limited to the lifetime of the program. When it stops, they’re gone.

With the Chrome alarm APIs, you can set an alarm that lasts as long as the app is installed, even if its background page goes inactive. You create such an alarm with chrome.alarms.create:

chrome.alarms.create(name, alarmInfo)

The second argument is an object that has the following three properties:

When the alarm should first fire, in milliseconds past the current time (
How long to delay until the alarm first fires
How long to wait between firings

One of the when and delayInMinutes properties is required, and periodInMinutes should be present only if you want the alarm to fire more than once.

When an alarm fires, it triggers a chrome.alarms.onAlarm event, the callback function of which receives an Alarm object as its argument, indicating which alarm fired. Its most important property is name.

You clear an alarm by using chrome.alarms.clear:

chrome.alarms.clear(name, callback)

The callback function has a Boolean argument that indicates whether the alarm was cleared.

There are also APIs to get information ...

Get Programming Chrome Apps now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.