reroute.js (891B)
1 onfetch = function (e) { 2 if (e.request.url.includes("Referer")) { 3 // Silently rewrite the referrer so the referrer test passes since the 4 // document/worker isn't aware of this service worker. 5 var url = e.request.url.substring(0, e.request.url.indexOf("?")); 6 url += "?headers=" + JSON.stringify({ Referer: self.location.href }); 7 8 e.respondWith( 9 e.request.text().then(function (text) { 10 var body = text === "" ? undefined : text; 11 var mode = 12 e.request.mode == "navigate" ? "same-origin" : e.request.mode; 13 return fetch(url, { 14 method: e.request.method, 15 headers: e.request.headers, 16 body, 17 mode, 18 credentials: e.request.credentials, 19 redirect: e.request.redirect, 20 cache: e.request.cache, 21 }); 22 }) 23 ); 24 return; 25 } 26 e.respondWith(fetch(e.request)); 27 };