Navigator.setAppBadge()

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

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

contents Optional

A number which will be used as the value of the badge. If contents is 0 then a badge not containing a count will be displayed.

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

Specification
Badging API
# setappbadge-method

Browser compatibility

BCD tables only load in the browser

See also