You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Angulars Service Worker - "beforePushNotification" #55641
Which @angular/* package(s) are relevant/related to the feature request?
Angular 17.3.x and @angular/pwa
Description
Angulars ngsw-worker.js shows notification at any time a "push" event occurs. However, receiving push notifications when the app is open and in the foreground is not a good user experience. Angular's service worker does not offer a direct way to determine whether a notification should finally be displayed or not. The "onPush" method cannot be overwritten, at most it can be extended - which does not lead to the desired result.
I tried things with a custom service worker like this:
self.addEventListener("push", (event) => {
console.log("Push event detected, but notifications are suppressed.");
event.preventDefault();
event.stopPropagation();
event.waitUntil(
(async function () {
console.log("Received push", event.data.json());
event.data.json().notification.title = null;
return;
})()
);
});
importScripts("./ngsw-worker.js");
but without success (It doesn't matter whether importScripts is at the top or at the bottom)
Proposed solution
A option to set, or a optional function which will return a boolean, like this:
Browsers currently support only userVisibleOnly: true.
If the subscription is made with userVisibleOnly: true and the app does not display the notifications, then the browser could revoke the subscription.
Activity
Flo0806 commentedon May 3, 2024
In the end we can always add our own service worker. But that was not my goal. I have found a solution - it's not the best way to go, but it works:
milen-yordanov commentedon Jul 1, 2024
The app should ALWAYS display push notifications.
See:
https://developer.mozilla.org/en-US/docs/Web/API/PushManager/subscribe
https://web.dev/articles/push-notifications-subscribing-a-user#uservisibleonly_options
Browsers currently support only
userVisibleOnly: true.If the subscription is made with
userVisibleOnly: trueand the app does not display the notifications, then the browser could revoke the subscription.See:
https://meta.discourse.org/t/ios-notifications-can-lose-permission-to-push-if-the-user-is-currently-active/290225
https://webkit.org/blog/12945/meet-web-push/
JeanMeche commentedon Aug 27, 2025
Per #63364, we won't be addressing this issue.
The message is also visible here: https://angular.dev/ecosystem/service-workers
angular-automatic-lock-bot commentedon Sep 27, 2025
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.