web api instance method
Navigator: setAppBadge() method
Secure context
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
setAppBadge()
setAppBadge(contents)
Parameters
contentsOptional- : A
Numberwhich will be used as the value of the badge. Ifcontentsis0then the badge will be set tonothing, indicating a cleared badge.
- : A
Return value
A Promise that resolves with undefined.
Exceptions
InvalidStateErrorDOMException- : Thrown if the document is not fully active.
SecurityErrorDOMException- : Thrown if the call was blocked by the same-origin policy.
NotAllowedErrorDOMException- : Thrown if
stateis notgranted.
- : Thrown if
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
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.