For a userscript, I need code that caches an Audio file upon fetch and replaces a request on a re-fetch, however I couldn’t find a way to register a serviceworker under a userscript that can intercept fetch requests. If I create a worker through
var blob = new Blob(["self.addEventListener('fetch', event => {console.log('Intercepted request:', event.request.url);});"
],{type: 'text/javascript'});
var worker = new Worker(URL.createObjectURL(blob));
It registers the worker but the fetch event does not trigger on fetch events on the page. Is there a way to circumvent this behaviour? I cannot use navigator.serviceworker.register
as it requires a URL relative to base URL.