@@ -249,7 +249,7 @@ export class ServiceWorker {
249249 const appId = await ServiceWorker . getAppId ( ) ;
250250
251251 for ( const rawNotification of notifications ) {
252- Log . debug ( 'Raw Notification from OneSignal:' , rawNotification ) ;
252+ Log . debug ( 'Raw Notification from OneSignal:' , JSON . stringify ( rawNotification ) ) ;
253253 const notification = ServiceWorker . buildStructuredNotificationObject ( rawNotification ) ;
254254
255255 const notificationReceived : NotificationReceived = {
@@ -266,10 +266,16 @@ export class ServiceWorker {
266266 notificationEventPromiseFns . push ( ( notif => {
267267 return ServiceWorker . displayNotification ( notif )
268268 . then ( ( ) => {
269+ console . log ( `Notification displayed then 1` ) ;
269270 return ServiceWorker . workerMessenger . broadcast ( WorkerMessengerCommand . NotificationDisplayed , notif ) . catch ( e => Log . error ( e ) ) ;
270271 } )
271- . then ( ( ) => ServiceWorker . executeWebhooks ( 'notification.displayed' , notif )
272- . then ( ( ) => ServiceWorker . sendConfirmedDelivery ( notif ) ) . catch ( e => Log . error ( e ) ) ) ;
272+ . then ( ( ) => {
273+ console . log ( `Notification displayed then 2` ) ;
274+ ServiceWorker . executeWebhooks ( 'notification.displayed' , notif ) } )
275+ . then ( ( ) => {
276+ console . log ( `Notification displayed then 3` ) ;
277+ ServiceWorker . sendConfirmedDelivery ( notif )
278+ } ) . catch ( e => Log . error ( e ) ) ;
273279 } ) . bind ( null , notification ) ) ;
274280 }
275281
@@ -631,6 +637,7 @@ export class ServiceWorker {
631637 const persistNotification = await Database . get ( 'Options' , 'persistNotification' ) ;
632638 // Get app ID for tag value
633639 const appId = await ServiceWorker . getAppId ( ) ;
640+ Log . debug ( "appId" , appId ) ;
634641
635642 notification . heading = notification . heading ? notification . heading : defaultTitle ;
636643 notification . icon = notification . icon ? notification . icon : ( defaultIcon ? defaultIcon : undefined ) ;
@@ -644,8 +651,10 @@ export class ServiceWorker {
644651 overrides = { } ;
645652 notification = { ...notification , ...overrides } ;
646653
654+ Log . debug ( "before ensureNotificationResourcesHttps" , ) ;
647655 ServiceWorker . ensureNotificationResourcesHttps ( notification ) ;
648656
657+ Log . debug ( "after ensureNotificationResourcesHttps" , ) ;
649658 const notificationOptions = {
650659 body : notification . content ,
651660 icon : notification . icon ,
@@ -679,7 +688,7 @@ export class ServiceWorker {
679688 seconds unless requireInteraction is set to true. See:
680689 https://developers.google.com/web/updates/2015/10/notification-requireInteractiom
681690 */
682- requireInteraction : extra . persistNotification ,
691+ // requireInteraction: extra.persistNotification,
683692 /*
684693 On Chrome 50+, by default notifications replacing
685694 identically-tagged notifications no longer vibrate/signal the user
@@ -708,9 +717,12 @@ export class ServiceWorker {
708717 long to pause. For example [300, 100, 400] would vibrate 300ms,
709718 pause 100ms, then vibrate 400ms.
710719 */
711- vibrate : notification . vibrate
720+ vibrate : notification . vibrate ,
721+ requireInteraction : true , // Forces notification to stay visible
722+ silent : false
712723 } ;
713724
725+ Log . debug ( "before showNotification" , self . registration , notification . heading , notificationOptions ) ;
714726 return self . registration . showNotification ( notification . heading , notificationOptions ) ;
715727 }
716728
@@ -720,9 +732,12 @@ export class ServiceWorker {
720732 * @param url
721733 */
722734 static shouldOpenNotificationUrl ( url ) {
723- return ( url !== 'javascript:void(0);' &&
724- url !== 'do_not_open' &&
725- ! Utils . contains ( url , '_osp=do_not_open' ) ) ;
735+ const shouldOpen = ( url !== 'javascript:void(0);' &&
736+ url !== 'do_not_open' &&
737+ ! Utils . contains ( url , '_osp=do_not_open' ) ) ;
738+
739+ Log . debug ( `Called %cshouldOpenNotificationUrl(${ url } ):` , url , shouldOpen ) ;
740+ return shouldOpen ;
726741 }
727742
728743 /**
@@ -744,6 +759,7 @@ export class ServiceWorker {
744759 * notification body was clicked.
745760 */
746761 static async getNotificationUrlToOpen ( notification ) : Promise < string > {
762+ Log . debug ( "getNotificationUrlToOpen" , JSON . stringify ( notification ) ) ;
747763 // Defaults to the URL the service worker was registered
748764 // TODO: This should be fixed for HTTP sites
749765 let launchUrl = location . origin ;
@@ -753,9 +769,10 @@ export class ServiceWorker {
753769 if ( dbDefaultNotificationUrl )
754770 launchUrl = dbDefaultNotificationUrl ;
755771
772+ Log . debug ( "SW URL" , launchUrl , dbDefaultNotificationUrl , notification ?. url )
756773 // If the user clicked an action button, use the URL provided by the action button
757774 // Unless the action button URL is null
758- if ( notification . action ) {
775+ if ( notification && notification . action ) {
759776 // Find the URL tied to the action button that was clicked
760777 for ( const button of notification . buttons ) {
761778 if ( button . action === notification . action &&
@@ -764,7 +781,7 @@ export class ServiceWorker {
764781 launchUrl = button . url ;
765782 }
766783 }
767- } else if ( notification . url &&
784+ } else if ( notification && notification . url &&
768785 notification . url !== '' ) {
769786 // The user clicked the notification body instead of an action button
770787 launchUrl = notification . url ;
@@ -778,7 +795,7 @@ export class ServiceWorker {
778795 * dismissed by clicking the 'X' icon. See the notification close event for the dismissal event.
779796 */
780797 static async onNotificationClicked ( event : NotificationEventInit ) {
781- Log . debug ( ` Called %conNotificationClicked( ${ JSON . stringify ( event , null , 4 ) } ):` , Utils . getConsoleStyle ( 'code' ) , event ) ;
798+ Log . debug ( " Called onNotificationClicked" , JSON . stringify ( event ) ) ;
782799
783800 // Close the notification first here, before we do anything that might fail
784801 event . notification . close ( ) ;
@@ -805,9 +822,10 @@ export class ServiceWorker {
805822 const appId = await ServiceWorker . getAppId ( ) ;
806823 const deviceType = DeviceRecord . prototype . getDeliveryPlatform ( ) ;
807824
825+ Log . info ( "NotificationClicked appId" , appId ) ;
808826 let saveNotificationClickedPromise : Promise < void > | undefined ;
809827 const notificationClicked : NotificationClicked = {
810- notificationId : notificationData . id ,
828+ notificationId : notificationData ? .id ,
811829 appId,
812830 url : launchUrl ,
813831 timestamp : new Date ( ) . getTime ( ) ,
0 commit comments