JavaScript Navigator clearAppBadge() Method

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs

What You’ll Learn

navigator.clearAppBadge() is part of the Badging API. Learn how to remove an app icon badge after unread items are handled, pair it with setAppBadge(), use secure contexts, and try five beginner examples.

01

Kind

Method

02

Returns

Promise<undefined>

03

Status

Limited availability

04

Context

Secure (HTTPS)

05

API family

Badging API

06

Pairs with

setAppBadge()

Introduction

Installed Progressive Web Apps can show a small badge on their icon — a number like 3 for unread messages, or a simple flag/dot. That badge is set with navigator.setAppBadge().

When nothing is left to highlight (inbox empty, tasks done), call navigator.clearAppBadge() to remove it. The badge value becomes nothing, and the icon returns to a clean state.

💡
Installed apps first

Badging is most useful for PWAs / home-screen apps. In a normal browser tab the methods may exist but have no visible icon to badge — always feature-detect and treat badging as progressive enhancement.

Understanding the clearAppBadge() Method

clearAppBadge() is the dedicated “remove badge” call in the Badging API.

  • No parameters — just call navigator.clearAppBadge().
  • Sets badge to nothing — no number / flag on the icon.
  • Returns a Promise — resolves with undefined on success.
  • Secure context — HTTPS / localhost required.
  • May reject — e.g. document not fully active, same-origin issues, or permission not granted (NotAllowedError).
  • AlternativesetAppBadge(0) also clears the badge.

📝 Syntax

General form of the method:

JavaScript
navigator.clearAppBadge()

Parameters

  • None.

Return value

  • A Promise that resolves with undefined.

Common patterns

JavaScript
// MDN: clear after messages are read
navigator.clearAppBadge();

// Safer async pattern with feature detect
async function clearBadgeSafe() {
  if (!navigator.clearAppBadge) {
    return "Badging API not supported";
  }
  try {
    await navigator.clearAppBadge();
    return "Badge cleared";
  } catch (err) {
    return "clearAppBadge error: " + err.name;
  }
}

// Pair with setAppBadge for unread counts
async function syncUnreadBadge(unread) {
  if (!navigator.setAppBadge || !navigator.clearAppBadge) return;
  if (unread > 0) {
    await navigator.setAppBadge(unread);
  } else {
    await navigator.clearAppBadge();
  }
}

⚡ Quick Reference

GoalCode
Feature detecttypeof navigator.clearAppBadge === "function"
Clear the badgeawait navigator.clearAppBadge()
Set a countawait navigator.setAppBadge(n)
Clear via setawait navigator.setAppBadge(0)
Secure context?window.isSecureContext

🔍 At a Glance

Four facts to remember about navigator.clearAppBadge().

Returns
Promise

Resolves undefined

Availability
Limited

Not Baseline

Context
HTTPS

Secure required

Effect
nothing

Badge cleared

📋 clearAppBadge() vs setAppBadge()

clearAppBadge()setAppBadge()
PurposeRemove the badgeShow a number or flag
ParametersNoneOptional contents number
Badge resultnothing (cleared)Number, flag (no arg), or nothing if 0
Return typePromise<undefined>Promise<undefined>
Typical useInbox empty / all readUnread count > 0

Examples Gallery

Examples follow MDN Badging API patterns. Prefer Try It Yourself — a visible badge usually needs an installed PWA / home-screen app on a supporting OS.

📚 Getting Started

Detect the Badging API and clear a badge the MDN way.

Example 1 — Feature Detection

Check clearAppBadge / setAppBadge and secure context together.

JavaScript
const lines = [
  "clearAppBadge: " +
    (typeof navigator.clearAppBadge === "function" ? "available" : "missing"),
  "setAppBadge: " +
    (typeof navigator.setAppBadge === "function" ? "available" : "missing"),
  "isSecureContext: " + window.isSecureContext
];
console.log(lines.join("\n"));
Try It Yourself

How It Works

If the methods are missing, skip badging and rely on in-app unread UI only.

Example 2 — Clear the Badge (MDN)

MDN’s basic call once all messages have been read.

JavaScript
if (!navigator.clearAppBadge) {
  console.log("clearAppBadge not supported");
} else {
  navigator.clearAppBadge().then(
    () => console.log("Badge cleared (or no-op on this platform)"),
    (err) => console.log("Error: " + err.name)
  );
}
Try It Yourself

How It Works

Always handle the Promise rejection — permission or platform limits can reject the call.

📈 Practical Patterns

Sync unread counts, compare with setAppBadge(0), and wrap errors safely.

Example 3 — Sync Badge From Unread Count

Set a number when unread > 0; clear when the inbox is empty.

JavaScript
async function syncUnreadBadge(unread) {
  if (!navigator.setAppBadge || !navigator.clearAppBadge) {
    return "Badging API not supported";
  }
  try {
    if (unread > 0) {
      await navigator.setAppBadge(unread);
      return "Badge set to " + unread;
    }
    await navigator.clearAppBadge();
    return "Badge cleared (unread = 0)";
  } catch (err) {
    return "Badge sync error: " + err.name;
  }
}

syncUnreadBadge(0).then(console.log);
Try It Yourself

How It Works

Call this helper whenever your unread count changes so the icon stays honest.

Example 4 — clearAppBadge() vs setAppBadge(0)

Both clear the badge; pick the clearer intent for your code.

JavaScript
async function compareClearStyles() {
  if (!navigator.clearAppBadge || !navigator.setAppBadge) {
    return "Badging API not supported";
  }
  // Dedicated clear
  await navigator.clearAppBadge();
  // Equivalent clear via set
  await navigator.setAppBadge(0);
  return "Both clearAppBadge() and setAppBadge(0) clear the badge";
}

compareClearStyles().then(console.log);
Try It Yourself

How It Works

Prefer clearAppBadge() when reading code aloud: “clear the badge” is clearer than “set zero.”

Example 5 — Safe Clear Helper

Beginner wrapper that never throws into your UI flow.

JavaScript
async function clearBadgeSafe() {
  if (typeof navigator.clearAppBadge !== "function") {
    return { ok: false, reason: "unsupported" };
  }
  if (!window.isSecureContext) {
    return { ok: false, reason: "insecure-context" };
  }
  try {
    await navigator.clearAppBadge();
    return { ok: true, reason: "cleared" };
  } catch (err) {
    return { ok: false, reason: err.name };
  }
}

clearBadgeSafe().then((result) => {
  console.log(JSON.stringify(result));
});
Try It Yourself

How It Works

Use structured results so your app can log, ignore, or show a soft message without crashing.

🚀 Common Use Cases

  • Messaging apps — clear the badge when the inbox is empty.
  • Todo / reminders — remove the icon badge after tasks are completed.
  • Turn-based games — clear when it is no longer the player’s turn.
  • Notification hygiene — keep the dock / home screen honest after users catch up.
  • Progressive PWAs — enhance installed apps without requiring badges for core UX.

🧠 How navigator.clearAppBadge() Works

1

Detect Badging support

Check navigator.clearAppBadge on a secure page.

Detect
2

Decide when to clear

Usually when unread / pending count reaches zero.

State
3

Await clearAppBadge()

The Promise sets the badge value to nothing.

Clear
4

Icon looks clean again

On supporting installed apps, the badge indicator is removed.

📝 Notes

  • Limited availability (not Baseline) — feature-detect always.
  • Not Deprecated, Experimental, or Non-standard — no status banner required (MDN/BCD).
  • Secure context required (HTTPS / localhost).
  • Returns a Promise; pair with navigator.setAppBadge() for counts.
  • Related: deprecatedReplaceInURN(), canShare(), serviceWorker, Window.

Limited Availability Support

navigator.clearAppBadge() belongs to the Badging API and is not Baseline. Support is strongest for installed PWAs on Chromium platforms and Safari (home screen / macOS Sonoma+). Firefox generally lacks support. Always feature-detect, use HTTPS, and treat badges as progressive enhancement.

Limited availability · Not Baseline

Navigator.clearAppBadge()

Promise that clears the app icon badge (sets badge to nothing).

Limited Not Baseline
Google Chrome Badging for installed apps (OS-dependent)
Limited
Microsoft Edge Follow Chromium Badging support
Limited
Apple Safari Home screen / installed web apps (version-dependent)
Limited
Opera Often follows Chromium where Badging exists
Limited
Mozilla Firefox Typically unavailable — feature-detect
Unavailable
Internet Explorer No Badging / clearAppBadge support
Unavailable
clearAppBadge() Limited

Bottom line: Detect clearAppBadge, clear when unread is zero, handle Promise rejections, and never rely on badges for critical information.

Conclusion

navigator.clearAppBadge() removes the app icon badge when there is nothing left to highlight. Detect support, clear after unread counts hit zero, handle Promise errors, and keep in-app indicators as the source of truth.

Continue with deprecatedReplaceInURN(), canShare(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Feature-detect navigator.clearAppBadge
  • Clear when unread / pending reaches zero
  • Use HTTPS / localhost
  • await and catch Promise rejections
  • Keep in-app unread UI as the real source of truth

❌ Don’t

  • Assume Baseline support everywhere
  • Rely on a visible badge in a normal browser tab
  • Ignore NotAllowedError / permission failures
  • Leave stale badges after users catch up
  • Use badges for security-critical alerts only

Key Takeaways

Knowledge Unlocked

Five things to remember about clearAppBadge()

Clear the icon badge when nothing is left unread.

5
Core concepts
02

Availability

Limited

Not Baseline
🔒 03

Context

secure HTTPS

Required
🔄 04

Effect

badge = nothing

Cleared
🎯 05

Pair

setAppBadge()

Counts

❓ Frequently Asked Questions

It clears a badge on the current app's icon by setting the badge to nothing — removing the numeric or flag indicator from the installed PWA / home-screen icon.
No. MDN/BCD mark it as standard-track and not Experimental or Deprecated. It is Limited availability (not Baseline), so always feature-detect. No Deprecated / Experimental / Non-standard status banner is required.
Yes. The Badging API is a secure-context feature (HTTPS or localhost) in supporting browsers.
A Promise that resolves with undefined when the badge is cleared (or when the call succeeds).
Both clear the badge. clearAppBadge() is the dedicated clear method. Passing 0 to setAppBadge() also sets the badge to nothing. Prefer clearAppBadge() when your intent is simply "remove the badge."
Commonly after the user has read all messages or cleared pending items — MDN's example: once all messages are read, call clearAppBadge() to remove the notification badge.
Did you know?

Calling navigator.setAppBadge() with no argument usually shows a flag/dot (not a number). Calling setAppBadge(0) or clearAppBadge() removes that indicator entirely.

Explore deprecatedReplaceInURN() Next

Learn the temporary Fenced Frame URN substitution API.

deprecatedReplaceInURN() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful