File tree Expand file tree Collapse file tree 2 files changed +14
-11
lines changed
Expand file tree Collapse file tree 2 files changed +14
-11
lines changed Original file line number Diff line number Diff line change @@ -61,18 +61,21 @@ async function fetchWithCache(request) {
6161// Push Notifications
6262// -----------------------------------------------------------------------------
6363self . addEventListener ( "push" , ( event ) => {
64- if ( ! event . data || ! event . data . text ( ) ) {
65- return ;
66- }
64+ event . waitUntil ( ( async ( ) => {
65+ let notification ;
6766
68- const notification = JSON . parse ( event . data . text ( ) ) ;
69- if ( ! notification ) {
70- return ;
71- }
67+ try {
68+ notification = event . data ? event . data . json ( ) : null ;
69+ } catch {
70+ notification = null ;
71+ }
7272
73- event . waitUntil (
74- showNotification ( self . registration , notification )
75- ) ;
73+ if ( ! notification ) {
74+ return ;
75+ }
76+
77+ await showNotification ( self . registration , notification ) ;
78+ } ) ( ) ) ;
7679} ) ;
7780
7881self . addEventListener ( "message" , ( event ) => {
You can’t perform that action at this time.
0 commit comments