ServiceWorkerGlobalScope: activate event
The activate
event of the ServiceWorkerGlobalScope
interface is fired when a ServiceWorkerRegistration
acquires a new ServiceWorkerRegistration.active
worker.
This event is not cancelable and does not bubble.
Syntax
Use the event name in methods like addEventListener()
, or set an event handler property.
addEventListener('activate', event => { });
onactivate = event => { };
Event type
An ExtendableEvent
. Inherits from Event
.
Event properties
Doesn't implement any specific properties, but inherits properties from its parent, Event
.
Examples
The following snippet shows how you could use an activate
event handler to upgrade a cache.
globalScope.addEventListener('activate', function(event) {
var cacheAllowlist = ['v2'];
event.waitUntil(
caches.forEach(function(cache, cacheName) {
if (cacheAllowlist.indexOf(cacheName) == -1) {
return caches.delete(cacheName);
}
})
);
});
You can also set up the event handler using the onactivate
property:
globalScope.onactivate = function(event) {
...
};
Specifications
Specification |
---|
Service Workers 1 # service-worker-global-scope-activate-event |
Browser compatibility
BCD tables only load in the browser