// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
dictionary Alarm {
// Name of this alarm.
required DOMString name;
// 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.
required double scheduledTime;
// If not null, the alarm is a repeating alarm and will fire again in
// periodInMinutes minutes.
double periodInMinutes;
// Whether the alarm should persist across sessions (browser restarts).
required boolean persistAcrossSessions;
};
// TODO(mpcomplete): rename to CreateInfo when http://crbug.com/123073 is
// fixed.
dictionary AlarmCreateInfo {
// Name of this alarm.
DOMString name;
// Time at which the alarm should fire, in milliseconds past the epoch
// (e.g. Date.now() + n).
double when;
// Length of time in minutes after which the onAlarm event
// should fire.
//
//
double delayInMinutes;
// 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.
//
//
double periodInMinutes;
// Whether the alarm should persist across sessions (browser restarts). In
// Chrome, this defaults to true to match historical behavior, but you should
// set this explicitly to maximize compatibility across browsers.
boolean persistAcrossSessions;
};
// Listener callback for the onAlarm event.
// |alarm|: The alarm that has elapsed.
callback OnAlarmListener = undefined (Alarm alarm);
interface OnAlarmEvent : ExtensionEvent {
static undefined addListener(OnAlarmListener listener);
static undefined removeListener(OnAlarmListener listener);
static boolean hasListener(OnAlarmListener listener);
};
// Use the chrome.alarms API to schedule code to run
// periodically or at a specified time in the future.
interface Alarms {
// 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 30 seconds but may delay them an arbitrary amount
// more. That is, setting delayInMinutes or
// periodInMinutes to less than 0.5 will not be
// honored and will cause a warning. when can be set to less
// than 30 seconds after "now" without warning but won't actually cause the
// alarm to fire for at least 30 seconds.
//
// 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.
//
// |name|: Optional name to identify this alarm. Defaults to the empty
// string.
// |alarmInfo|: 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.
// |Returns|: Promise that resolves when the alarm has been created.
static Promise create(
optional DOMString name,
AlarmCreateInfo alarmInfo);
// Retrieves details about the specified alarm.
// |name|: The name of the alarm to get. Defaults to the empty string.
// |PromiseValue|: alarm
static Promise get(optional DOMString name);
// Gets an array of all the alarms.
// |PromiseValue|: alarms
static Promise> getAll();
// Clears the alarm with the given name.
// |name|: The name of the alarm to clear. Defaults to the empty string.
// |PromiseValue|: wasCleared
static Promise clear(optional DOMString name);
// Clears all alarms.
// |PromiseValue|: wasCleared
static Promise clearAll();
// Fired when an alarm has elapsed. Useful for event pages.
static attribute OnAlarmEvent onAlarm;
};
partial interface Browser {
static attribute Alarms alarms;
};