Welcome What's new in Chrome extensions Getting started API Reference Samples
Welcome What's new in Chrome extensions Getting started API Reference Samples

chrome.alarms

  • Description

    Use the chrome.alarms API to schedule code to run periodically or at a specified time in the future.

  • Permissions
    alarms

Summary

  • Types
  • Methods
    clear(name?: string): Promise<object>
    clear(name?: string, callback?: function): void
    clearAll(): Promise<object>
    clearAll(callback?: function): void
    create(name?: string, alarmInfo: AlarmCreateInfo): void
    get(name?: string): Promise<object>
    get(name?: string, callback: function): void
    getAll(): Promise<object>
    getAll(callback: function): void
  • Events

Types

Alarm

Properties

  • name
    string

    Name of this alarm.

  • periodInMinutes
    number optional

    If not null, the alarm is a repeating alarm and will fire again in periodInMinutes minutes.

  • scheduledTime
    number

    Time at which this alarm was scheduled to fire, in milliseconds past the epoch (e.g. Date.now() + n). For performance reasons, the alarm may have been delayed an arbitrary amount beyond this.

AlarmCreateInfo

Properties

  • delayInMinutes
    number optional

    Length of time in minutes after which the onAlarm event should fire.

  • periodInMinutes
    number optional

    If set, the onAlarm event should fire every periodInMinutes minutes after the initial event specified by when or delayInMinutes. If not set, the alarm will only fire once.

  • when
    number optional

    Time at which the alarm should fire, in milliseconds past the epoch (e.g. Date.now() + n).

Methods

clear

clear(name?: string): Promise<object>
clear(name?: string, callback?: function): void
Promise

Clears the alarm with the given name.

Parameters

  • name
    string optional

    The name of the alarm to clear. Defaults to the empty string.

Result

  • return/callback
    async

    The clear method provides its result via callback or returned as a Promise (MV3 only).

    • wasCleared
      boolean

clearAll

clearAll(): Promise<object>
clearAll(callback?: function): void
Promise

Clears all alarms.

Result

  • return/callback
    async

    The clearAll method provides its result via callback or returned as a Promise (MV3 only).

    • wasCleared
      boolean

create

create(name?: string, alarmInfo: AlarmCreateInfo): void

Creates an alarm. Near the time(s) specified by alarmInfo, the onAlarm event is fired. If there is another alarm with the same name (or no name if none is specified), it will be cancelled and replaced by this alarm.

In order to reduce the load on the user's machine, Chrome limits alarms to at most once every 1 minute but may delay them an arbitrary amount more. That is, setting delayInMinutes or periodInMinutes to less than 1 will not be honored and will cause a warning. when can be set to less than 1 minute after "now" without warning but won't actually cause the alarm to fire for at least 1 minute.

To help you debug your app or extension, when you've loaded it unpacked, there's no limit to how often the alarm can fire.

Parameters

  • name
    string optional

    Optional name to identify this alarm. Defaults to the empty string.

  • Describes when the alarm should fire. The initial time must be specified by either when or delayInMinutes (but not both). If periodInMinutes is set, the alarm will repeat every periodInMinutes minutes after the initial event. If neither when or delayInMinutes is set for a repeating alarm, periodInMinutes is used as the default for delayInMinutes.

get

get(name?: string): Promise<object>
get(name?: string, callback: function): void
Promise

Retrieves details about the specified alarm.

Parameters

  • name
    string optional

    The name of the alarm to get. Defaults to the empty string.

Result

  • return/callback
    async

    The get method provides its result via callback or returned as a Promise (MV3 only).

getAll

getAll(): Promise<object>
getAll(callback: function): void
Promise

Gets an array of all the alarms.

Result

  • return/callback
    async

    The getAll method provides its result via callback or returned as a Promise (MV3 only).

Events

onAlarm

onAlarm.addListener(listener: function)

Fired when an alarm has elapsed. Useful for event pages.

Event

  • listener
    function

    The listener parameter should be a function that looks like this:

    (alarm: Alarm) => {...}
    • alarm

      The alarm that has elapsed.

We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.