Navigator: setAppBadge() method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The setAppBadge() method of the Navigator interface sets a badge on the icon associated with this app. If a value is passed to the method, this will be set as the value of the badge. Otherwise the badge will display as a dot, or other indicator as defined by the platform.

Syntax

js
setAppBadge()
setAppBadge(contents)

Parameters

contents Optional

A number which will be used as the value of the badge. If contents is 0 then the badge will be set to nothing, indicating a cleared badge.

Return value

A Promise that resolves with undefined.

Exceptions

InvalidStateError DOMException

Thrown if the document is not fully active.

SecurityError DOMException

Thrown if the call was blocked by the same-origin policy.

NotAllowedError DOMException

Thrown if PermissionStatus.state is not granted.

Examples

In the example below an unread count is passed to setAppBadge(). The badge should then display 30.

js
const unread = 30;
navigator.setAppBadge(unread);

Specifications

Specification
Badging API
# setappbadge-method

Browser compatibility

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
setAppBadge

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.

See also