You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To accompany the new workbox-window library in v4, and standardize the functionality that's needed for the skipWaiting message handler proposed in #1753 as well as what's already implemented in
I'm proposing a new set of methods on workbox.core:
registerMessageCallback({messageType, callback}) will take care of adding in a message event handler (if one doesn't already exist) that will in turn check for incoming messages whose event.data.type === messageType, and when found, run await callback(event) for each registered event. The callback mechanism will be wrapped in event.waitUntil() (for browsers that support it: MessageEvent within the SW global should have waitUntil() w3c/ServiceWorker#669 (comment))
unregisterMessageCallback({messageType, callback}) will do the opposite, and either unregister a specific callback, or if callback is null, unregister all callbacks for the given messageType.
I think that keeping track of messageType values can be done on a per-module basis, i.e. the constant used by workbox-broadcast-cache-update can be defined locally there.
One additional area for discussion is whether this proposal can end up powering the mechanism that's already in place in workbox.core for registering callbacks that can be run when there's a global QUOTA_EXCEEDED error. There's a lot of similarities, but invoking callbacks triggered by an exception is different from invoking callbacks triggered by a message event.
To accompany the new
workbox-windowlibrary in v4, and standardize the functionality that's needed for theskipWaitingmessage handler proposed in #1753 as well as what's already implemented inworkbox/packages/workbox-broadcast-cache-update/BroadcastCacheUpdate.mjs
Lines 185 to 207 in 208850c
I'm proposing a new set of methods on
workbox.core:registerMessageCallback({messageType, callback})will take care of adding in amessageevent handler (if one doesn't already exist) that will in turn check for incomingmessages whoseevent.data.type === messageType, and when found, runawait callback(event)for each registered event. The callback mechanism will be wrapped inevent.waitUntil()(for browsers that support it: MessageEvent within the SW global should have waitUntil() w3c/ServiceWorker#669 (comment))unregisterMessageCallback({messageType, callback})will do the opposite, and either unregister a specificcallback, or ifcallbackisnull, unregister all callbacks for the givenmessageType.I think that keeping track of
messageTypevalues can be done on a per-module basis, i.e. the constant used byworkbox-broadcast-cache-updatecan be defined locally there.One additional area for discussion is whether this proposal can end up powering the mechanism that's already in place in
workbox.corefor registering callbacks that can be run when there's a globalQUOTA_EXCEEDEDerror. There's a lot of similarities, but invoking callbacks triggered by an exception is different from invoking callbacks triggered by amessageevent.