When we were testing Widgets, we found an issue when opening a PWA using https://developer.mozilla.org/en-US/docs/Web/API/Clients/openWindow API from the service worker is not possible from the widgetclick handler. This is because client.openWindow API works only with some event handlers (notificationclick, paymentrequest and backgroundfetchclick).
We can add the support of adding the window interaction in widgetclick event but this API (openWindow) is gated for only user interaction events and widgetclick event can occur even without user interacting with the widgets (like widgetresume event on scrolling the widgets dashboard).
The proposed solution will be dividing the event in to two types of events.
“widgetclick” Event: Scoped only for user interaction with widgets (Action.Execute)
self.addEventListener(“widgetclick”, (event) => { if (event.action === “verb”) getClient().openWindow() });
When we were testing Widgets, we found an issue when opening a PWA using https://developer.mozilla.org/en-US/docs/Web/API/Clients/openWindow API from the service worker is not possible from the
widgetclick
handler. This is becauseclient.openWindow
API works only with some event handlers (notificationclick, paymentrequest and backgroundfetchclick).We can add the support of adding the window interaction in
widgetclick
event but this API (openWindow) is gated for only user interaction events andwidgetclick
event can occur even without user interacting with the widgets (likewidgetresume
event on scrolling the widgets dashboard).The proposed solution will be dividing the event in to two types of events.
“widgtinstall”, “widgetuninstall” and “widgetresume”: Handle widget lifecycle events
self.addEventListener(“widgetinstall”, (event) => { handleInstall() });
“widgetclick” Event: Scoped only for user interaction with widgets (Action.Execute)
self.addEventListener(“widgetclick”, (event) => { if (event.action === “verb”) getClient().openWindow() });