Title: Angulars Service Worker - "beforePushNotification" · Issue #55641 · angular/angular · GitHub
Open Graph Title: Angulars Service Worker - "beforePushNotification" · Issue #55641 · angular/angular
X Title: Angulars Service Worker - "beforePushNotification" · Issue #55641 · angular/angular
Description: 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...
Open Graph Description: 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. Ho...
X Description: 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 ...
Opengraph URL: https://github.com/angular/angular/issues/55641
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Angulars Service Worker - \"beforePushNotification\"","articleBody":"### Which @angular/* package(s) are relevant/related to the feature request?\r\n\r\nAngular 17.3.x and @angular/pwa\r\n\r\n### Description\r\n\r\nAngulars `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.\r\n\r\nI tried things with a custom service worker like this:\r\n\r\n```\r\nself.addEventListener(\"push\", (event) => {\r\n console.log(\"Push event detected, but notifications are suppressed.\");\r\n event.preventDefault();\r\n event.stopPropagation();\r\n\r\n event.waitUntil(\r\n (async function () {\r\n\r\n console.log(\"Received push\", event.data.json());\r\n event.data.json().notification.title = null;\r\n\r\n return;\r\n })()\r\n );\r\n});\r\n\r\nimportScripts(\"./ngsw-worker.js\");\r\n```\r\n\r\nbut without success (It doesn't matter whether `importScripts` is at the top or at the bottom)\r\n\r\n### Proposed solution\r\n\r\nA option to set, or a optional function which will return a boolean, like this:\r\n\r\n```\r\nthis.swPush.beforePushNotification = () => { return false; }\r\n```\r\n\r\n### Alternatives considered\r\n\r\nA way to override functions like \"onPush\" in the Service Worker itself.","author":{"url":"https://github.com/Flo0806","@type":"Person","name":"Flo0806"},"datePublished":"2024-05-02T18:03:11Z","url":"https://github.com/angular/angular/issues/55641"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:9a8a343e-b619-7630-701c-130073405251 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A704:31E99C:E57EFB:1339A48:6B01076E |
| html-safe-nonce | d5a2bc10fb7dc7ef0a9050bd1a7702a927705dd526ef6b45d83a6b864242711a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNzA0OjMxRTk5QzpFNTdFRkI6MTMzOUE0ODo2QjAxMDc2RSIsInZpc2l0b3JfaWQiOiI3ODgxOTQxNTExNzI4ODU4OTkwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 81ac3899275dacd2c61a38355c5452d525584313bfc3088289fc8da856a57d05 |
| hovercard-subject-tag | issue:2276162185 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/55641/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6d0fc01883a277855d05116c9ac54a8a287cac558615455f1cedb87b568242a7/angular/angular/issues/55641 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6d0fc01883a277855d05116c9ac54a8a287cac558615455f1cedb87b568242a7/angular/angular/issues/55641 |
| og:image:alt | 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. Ho... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Flo0806 |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width