MicrosoftEdge / MSEdgeExplainers

Home for explainer documents originated by the Microsoft Edge team
Creative Commons Attribution 4.0 International
1.31k stars 211 forks source link

Split Widget Events #613

Closed adolfdaniel closed 1 year ago

adolfdaniel commented 1 year ago

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.

  1. “widgtinstall”, “widgetuninstall” and “widgetresume”: Handle widget lifecycle events self.addEventListener(“widgetinstall”, (event) => { handleInstall() });

  2. “widgetclick” Event: Scoped only for user interaction with widgets (Action.Execute) self.addEventListener(“widgetclick”, (event) => { if (event.action === “verb”) getClient().openWindow() });