Enhance Web Push Example with Non-Interactive Subscription & Auto-Activation in Service Worker #1410
+260
−59
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes Issue #1408 by automating the push subscription process in the cookbook.push extension. Previously, users had to manually subscribe via the Service Worker DevTools. This update ensures the subscription is created automatically when the Service Worker activates.
Changes Implemented
background.js
Added event.waitUntil(subscribeUserVisibleOnlyFalse()); in the activate event to auto-subscribe users.
Improved logging for debugging.
Ensured userVisibleOnly = true for push notifications.
manifest.json
Added "gcm_sender_id": "103953800507" for better push compatibility.
popup.js
Improved error handling for subscription failures.
Added clear logs when subscribing/unsubscribing.
README.md
Updated instructions to include automatic subscription.
Added a template for send-push.js to help test push messages.
This update ensures a fully functional, real-world web push example without requiring manual DevTools interaction.
Fixes #1408