We've a PWA implemented on angular 7 and NodeJS as backend. Push notification are sent from backend with web-push and handled by the angular service worker service.
The behavior that we hope to have in Android is when the user clicks on the notification, the application opens in the device (i.e. the PWA come up from background and appear visible to the user).
Currently, the code seams to execute in the background but PWA does not come up from background (i.e. the user clicks in the push notification but nothing happens).
The push notification are handled by the angular service called SwPush on front-end, and delivered to app using the following code in the typical AppComponent component of an angular app:
export class AppComponent implements OnInit {
constructor(private swPush: SwPush) { }
ngOnInit(): void {
try {
if (this.swPush.isEnabled) {
this.swPush.notificationClicks.subscribe(
event => {
window.focus();
window.open(event.notification.data.url, '_self');
},
error => {
// handle error
}
);
}
} catch (err) {
// handle error
}
}
}
I have search all over the SO site and haven't found exactly this question. Comments about other SO questions in order to avoid round trip links to other SO answers:
- I have read this question, and in my case the console log inside the handler execute without problem
this other question seams to proposes a workaround adding code inside the service-worker library, but as far as I understand this is because they are using angular 5 instead of the angular 7 (where the SwPush service include the notificationclick handler). Any way, what I need is to simulate this line:
event.waitUtil(clients.openWindow(url));
Any idea on how to open the PWA when the user clicks on push notification when using the SwPush service of angular 7?