Badge
Display a badge on the app icon
Browser Support
Usage
Basic Badge Counter
<body {{ stimulus_controller('@pwa/badge') }}>
<div class="notifications">
<h2>Notifications</h2>
<p>You have <span id="notification-count">5</span> new notifications</p>
<button {{ stimulus_action('@pwa/badge', 'update', 'click', {counter: 5}) }}>
Set Badge to 5
</button>
<button {{ stimulus_action('@pwa/badge', 'clear', 'click') }}>
Clear Badge
</button>
</div>
</body>
<script>
document.addEventListener('pwa--badge:updated', (event) => {
console.log('Badge updated:', event.detail.counter);
});
</script>Dynamic Badge Update on Page Load
Real-time Badge Updates
Badge with WebSocket Updates
E-commerce Shopping Cart Badge
Parameters
Actions
update
updateclear
clearTargets
Events
pwa--badge:updated
pwa--badge:updatedBest Practices
Badge vs Push Notifications
Feature
Badge
Push Notification
Integration with Service Worker
Complete Example: Messaging App
Troubleshooting
Badge not appearing
Badge not updating
Badge count incorrect
Platform-Specific Behavior
Last updated
Was this helpful?