fune/toolkit/components/url-classifier/tests/mochitest/sw_worker.js
Dimi Lee 8f56bdc39d Bug 1437626 - P4. Test requests sent in a service worker is classified r=baku
This patches does the following:
1. Test fetch in service worker should be classified.
2. Test requests should not be classified when it is whitelisted.
3. Test requests should not be classified when it is a first-party.

Depends on D80184

Differential Revision: https://phabricator.services.mozilla.com/D80185
2020-07-08 12:27:14 +00:00

10 lines
325 B
JavaScript

self.addEventListener("fetch", function(event) {
let sep = "synth.html?";
let idx = event.request.url.indexOf(sep);
if (idx > 0) {
let url = event.request.url.substring(idx + sep.length);
event.respondWith(fetch(url, { credentials: "include" }));
} else {
event.respondWith(fetch(event.request));
}
});