Abstract

This specification defines an API to schedule a task at a specified time. When the indicated time is reached, the
application that scheduled the task will be notified via a functional event on a service worker. A task event will be delivered to a service worker, regardless
of whether the application is active on user agent. Applications such as an alarm clock or an
auto-updater may utilize this API to perform certain action at a specified time.

2
Conformance

This specification defines conformance criteria for a single product: the user agent that implements
the interfaces that it contains.

Implementations that use ECMAScript to implement the APIs defined in this specification MUST implement them in a manner
consistent with the ECMAScript Bindings defined in the
Web IDL specification[WEBIDL], as this specification uses that
specification and terminology.

The taskScheduler attribute provides the developer access to a
TaskScheduler.

5.2
Interface TaskScheduler

The TaskScheduler interface exposes methods to get, set or remove scheduled tasks. ScheduledTasks are
application specific, so there is no way to see the tasks scheduled by other applications nor to modify them.
Developers should set an ontask event handler in the associated service worker to listen for the task event when scheduled tasks should be executed.

If an error occurs, run these substeps and then terminate these steps:

Let error be a new DOMException exception whose name is the same as the error
returned.

Run resolver's internal reject algorithm with error as value.

When the operation completes successfully, run these substeps:

Let tasks be a new array containing the ScheduledTask objects that were retrieved.

Run resolver's intenal fulfill algorithm with tasks as value.

When invoked, the add(time[, data]) method
must run the following steps:

Make a request to the system to schedule a new task for the current application that will trigger at the given
time (number of milliseconds since the epoch). If the time argument is in the past, the task
will be executed as soon as possible, asynchronously. The system must associate the
JSON-serializable data with the task if provided.

Let promise be a new Promise object and resolver its associated resolver.

If an error occurs, run these substeps and then terminate these steps:

Let error be a new DOMException exception whose name is
"QuotaExceededError" if the data argument exceeds an implementation-dependent size limit, or
whose name is the same as the error returned otherwise.

To fire a service worker task event named e given task, fire an event named e with an event using the TaskEvent interface whose task attribute is initialized to a new ScheduledEvent object representing task.