Only handle requests with the same origin via the service worker

This commit is contained in:
schlagmichdoch 2025-02-25 18:19:38 +01:00
parent 4862ba3067
commit 31ec776fb3
1 changed files with 8 additions and 1 deletions

View File

@ -151,7 +151,14 @@ const updateCache = request => new Promise((resolve, reject) => {
// 2. If cache is not available: Fetch from network and update cache. // 2. If cache is not available: Fetch from network and update cache.
// This way, cached files are only updated if the cacheVersion is changed // This way, cached files are only updated if the cacheVersion is changed
self.addEventListener('fetch', function(event) { self.addEventListener('fetch', function(event) {
if (event.request.method === "POST") { const swOrigin = new URL(self.location.href).origin;
const requestOrigin = new URL(event.request.url).origin;
if (swOrigin !== requestOrigin) {
// Do not handle requests from other origin
event.respondWith(fetch(event.request));
}
else if (event.request.method === "POST") {
// Requests related to Web Share Target. // Requests related to Web Share Target.
event.respondWith((async () => { event.respondWith((async () => {
const share_url = await evaluateRequestData(event.request); const share_url = await evaluateRequestData(event.request);