dom / latest / navigator / setappbadge.html /

Navigator.setAppBadge()

The setAppBadge() method of the Navigator interface 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

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

NotSupportedError DOMException

The Navigator does not have a document that this action can be acted on.

Examples

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

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

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
setAppBadge
81
Windows and macOS only.
81
Windows and macOS only.
No
No
No
No
No
81
No
58
No
13.0

See also

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Navigator/setAppBadge