On our project we have CSP configured and passed in Response Headers. Also we have simple Service Worker which checking if it's possible to navigate to another page and if not redirecting to cached offline html page.
This is code of part of Service Worker for fetch event
self.addEventListener('fetch', function (event) {
event.respondWith(
// Try to find requested resource in the cache
caches
.match(event.request).then(function (response) {
// Fallback to network if it's not in cache
return response || fetch(event.request);
})
.catch(getFallbackResponse(event))
);
});
But when CSP configuration is changed and Service Worker was installed before this changes in CSP configuration we get
Refused to load the script '[url]' because it violates the following Content Security Policy directive: ... error. And as soon as we update or unregister Service Worker, new CSP configuration is applied.
Is it expected behaviour?