Skip to content

Commit 31ec776

Browse files
Only handle requests with the same origin via the service worker
1 parent 4862ba3 commit 31ec776

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

public/service-worker.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,14 @@ const updateCache = request => new Promise((resolve, reject) => {
151151
// 2. If cache is not available: Fetch from network and update cache.
152152
// This way, cached files are only updated if the cacheVersion is changed
153153
self.addEventListener('fetch', function(event) {
154-
if (event.request.method === "POST") {
154+
const swOrigin = new URL(self.location.href).origin;
155+
const requestOrigin = new URL(event.request.url).origin;
156+
157+
if (swOrigin !== requestOrigin) {
158+
// Do not handle requests from other origin
159+
event.respondWith(fetch(event.request));
160+
}
161+
else if (event.request.method === "POST") {
155162
// Requests related to Web Share Target.
156163
event.respondWith((async () => {
157164
const share_url = await evaluateRequestData(event.request);

0 commit comments

Comments
 (0)