diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /dom/serviceworkers/test/force_refresh_worker.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | dom/serviceworkers/test/force_refresh_worker.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/dom/serviceworkers/test/force_refresh_worker.js b/dom/serviceworkers/test/force_refresh_worker.js new file mode 100644 index 0000000000..8c8382493a --- /dev/null +++ b/dom/serviceworkers/test/force_refresh_worker.js @@ -0,0 +1,43 @@ +var name = "refresherCache"; + +self.addEventListener("install", function (event) { + event.waitUntil( + Promise.all([ + caches.open(name), + fetch("./sw_clients/refresher_cached.html"), + fetch("./sw_clients/refresher_cached_compressed.html"), + ]).then(function (results) { + var cache = results[0]; + var response = results[1]; + var compressed = results[2]; + return Promise.all([ + cache.put("./sw_clients/refresher.html", response), + cache.put("./sw_clients/refresher_compressed.html", compressed), + ]); + }) + ); +}); + +self.addEventListener("fetch", function (event) { + event.respondWith( + caches + .open(name) + .then(function (cache) { + return cache.match(event.request); + }) + .then(function (response) { + // If this is one of our primary cached responses, then the window + // must have generated the request via a normal window reload. That + // should be detectable in the event.request.cache attribute. + if (response && event.request.cache !== "no-cache") { + dump( + '### ### FetchEvent.request.cache is "' + + event.request.cache + + '" instead of expected "no-cache"\n' + ); + return Response.error(); + } + return response || fetch(event.request); + }) + ); +}); |