# Notification triggers (showTrigger)

> What Chrome's Notification Triggers proposal added to showNotification() behind a flag, the showTrigger option and TimestampTrigger, and why it ended.

Notification triggers were a Chrome proposal for scheduling persistent notifications at a future time, with no page open and no push message. The proposed `showNotification()` option, `showTrigger`, held a `TimestampTrigger` that told the browser when to display the notification. Chrome's documentation states that development has ended. The feature remains behind the experimental flag in Chromium, Chrome Platform Status records no signal from Firefox and WebKit, and MDN's `showNotification()` reference does not list `showTrigger`.

## Syntax

```js
registration.showNotification(title, { showTrigger: new TimestampTrigger(timestamp) })
registration.getNotifications({ includeTriggered: true })
```

Both forms exist only in Chromium with `chrome://flags/#enable-experimental-web-platform-features`
enabled ([Notification Triggers](https://developer.chrome.com/docs/web-platform/notification-triggers),
developer.chrome.com). The feature's Chrome Platform Status entry reads "In developer trial (Behind
a flag)" ([chromestatus.com](https://chromestatus.com/feature/5133150283890688)); the origin trials
Chrome ran for it were not followed by a launch.

## Parameters

| Parameter | Type | Meaning |
|---|---|---|
| `showTrigger` | `TimestampTrigger` | When to display the notification. The constructor takes a `DOMTimeStamp` in milliseconds since the epoch, read back as `trigger.timestamp`. |
| `includeTriggered` | boolean, on `getNotifications()` options | Include scheduled notifications that have not yet been displayed, so a page can list or cancel them with `notification.close()`. Default `false`. |

The proposal also discussed a `notificationclose` for cancelled triggers and a limit on how far
ahead a trigger may be set; neither was specified.

## Exceptions

None.

## Platform availability

No browser ships the option. Chromium keeps the implementation behind the experimental features
flag with the status above; Chrome Platform Status records no signal from Firefox and WebKit, and MDN's reference for
`showNotification()` lists `actions`, `badge`, `body`, `data`, `dir`, `icon`, `image`, `lang`,
`navigate`, `renotify`, `requireInteraction`, `silent`, `tag`, `timestamp`, and `vibrate` without
`showTrigger`. The stated reason for stopping was the inability to provide consistent and
reliable behaviour across platforms, which is the same constraint that limits
[periodic background sync](/reference/notifications/periodic-background-sync/).

## Examples

Scheduling and cancelling a trigger require the flag. Use server-side scheduling for production.

### Scheduling a reminder behind the flag

With the flag enabled, the trigger is one extra option. The `tag` lets a later call replace the
scheduled notification instead of adding a second one.

```js
async function scheduleReminder(registration, when, title) {
  await registration.showNotification(title, {
    tag: `reminder-${when}`,
    body: 'Starts in 10 minutes',
    showTrigger: new TimestampTrigger(when - 10 * 60 * 1000),
  });
}
```

The call stores the request. Chrome's documentation says that on desktop the
trigger fires only if Chrome is running, and that on Android it fires regardless.

### Cancelling a scheduled notification

`getNotifications({ includeTriggered: true })` returns scheduled entries alongside displayed
ones; closing one before its trigger cancels it.

```js
async function cancelReminder(registration, when) {
  const pending = await registration.getNotifications({ includeTriggered: true });
  for (const notification of pending) {
    if (notification.tag === `reminder-${when}`) notification.close();
  }
}
```

Without the flag the option object is ignored and `pending` contains only displayed
notifications, so the loop finds nothing to cancel.

### Detecting the option and falling back to server-side scheduling

The test is `'showTrigger' in Notification.prototype`, and it is `false` wherever the
experimental flag described below is off, which is the default in every shipping browser. The fallback is to store the schedule on the server and deliver
it with Web Push; the explainer notes that delivery at a precise time is not guaranteed, because connectivity and device sleep can delay it.

```js
async function remindAt(registration, when, title) {
  if ('showTrigger' in Notification.prototype) {
    return registration.showNotification(title, { showTrigger: new TimestampTrigger(when) });
  }
  // not supported anywhere without a flag: schedule on the server and deliver by Web Push
  await fetch('/api/reminders', { method: 'POST', body: JSON.stringify({ when, title }) });
}
```

The server-side path depends on connectivity at delivery time, which is the limitation the
proposal set out to remove and the reason it is still occasionally requested.

:::note
In Chromium, `showTrigger` and `TimestampTrigger` are gated by the `NotificationTriggers` runtime
feature, which `runtime_enabled_features.json5` marks `experimental`
([notification_options.idl](https://chromium.googlesource.com/chromium/src/+/main/third_party/blink/renderer/modules/notifications/notification_options.idl),
[runtime_enabled_features.json5](https://chromium.googlesource.com/chromium/src/+/main/third_party/blink/renderer/platform/runtime_enabled_features.json5),
chromium.googlesource.com). Experimental features are exposed by
`chrome://flags/#enable-experimental-web-platform-features`. Without it, `showTrigger` is not a member
of the options dictionary, so `'showTrigger' in Notification.prototype` is `false`, `TimestampTrigger`
is undefined, so `new TimestampTrigger(...)` throws a `ReferenceError` before `showNotification()` runs.
If an options object carries `showTrigger` anyway, `showNotification()` ignores the unknown member and
displays the notification immediately, as Web IDL does for dictionary members it does not define. Chrome Platform Status lists
the feature as "In developer trial (Behind a flag)"
([chromestatus.com](https://chromestatus.com/feature/5133150283890688)).
:::

## See also

- [Notification Triggers](https://developer.chrome.com/docs/web-platform/notification-triggers) (developer.chrome.com)
- [Notification Triggers explainer](https://github.com/beverloo/notification-triggers) (github.com)
- [Chrome Platform Status: Notification Triggers](https://chromestatus.com/feature/5133150283890688) (chromestatus.com)
- [Web Push and PushManager.subscribe()](/reference/notifications/web-push/)
- [Periodic background sync for content updates](/reference/notifications/periodic-background-sync/)
- [Notifications API](/reference/notifications/notifications-api/)