summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/content-security-policy/sandbox/support/sandboxed-service-worker.js
blob: d4971266f5cbc105f0381c8c40409050166b6564 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
self.addEventListener('fetch', function(event) {
    const url = new URL(event.request.url);
    if (url.pathname.indexOf('get-origin') != -1) {
      event.respondWith(new Promise(function(resolve) {
        resolve(new Response(JSON.stringify({
            origin: self.origin
          })));
        }));
    }
    else if (url.pathname.indexOf('fetch') != -1) {
      event.respondWith(fetch(url.searchParams.get('url'),
                              {mode: event.request.mode}));
    }
  });