Browse Source

Fix illegal constructor error for notifications on mobile

- Changed from new Notification() to registration.showNotification()
- Mobile browsers require ServiceWorkerRegistration API for notifications
- Added vibrate pattern and badge icon for better mobile experience

This fixes the "Illegal constructor" error when enabling push notifications
on Chrome for Android and other mobile browsers.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
master
HikeMap User 1 month ago
parent
commit
ca44c0aba5
  1. 14
      index.html

14
index.html

@ -5406,11 +5406,15 @@
updateNotificationUI(true);
updateStatus('Push notifications enabled!', 'success');
// Test notification
new Notification('HikeMap Notifications Active', {
body: 'You will receive alerts about new geocaches and trail updates',
icon: '/icon-192x192.png'
});
// Test notification using service worker
if ('serviceWorker' in navigator && registration) {
registration.showNotification('HikeMap Notifications Active', {
body: 'You will receive alerts about new geocaches and trail updates',
icon: '/icon-192x192.png',
badge: '/icon-72x72.png',
vibrate: [200, 100, 200]
});
}
}
} catch (error) {
console.error('Failed to setup push notifications:', error);

Loading…
Cancel
Save