kylepaulsen / ResourceOverride

An extension to help you gain full control of any website by redirecting traffic, replacing, editing, or inserting new content.
MIT License
470 stars 118 forks source link

Using Resource Override to override a JavaScript file that is loaded as a SharedWorker doesn't work #57

Open TomF-NVM opened 2 years ago

TomF-NVM commented 2 years ago

Here is some sample code creating a SharedWorker: ` const myWorker = new SharedWorker('worker.js') myWorker.port.start() myWorker.port.onmessage = function (e) { console.log('Message received from worker', e) }

window.setTimeout(() => { console.log('Posting message to worker') myWorker.port.postMessage('hello') }, 3000) `

If I place the worker file (worker.js) on the same server as the html that contains the above code, then I see console logs for messages going to a from the worker. However, if I host the worker locally with a resource override pointing at it, then creating the SharedWorker fails silently and the network tab shows the request as stalled with a status of (pending).

If I simply load the shared worker js file in a browser tab then Resource Override serves it fine, so it's not that RO is unable to serve the file to the browser. It just seems unable to serve the file for the purpose of being used as a Shared Worker.

I am using url -> url mapping with http-server -c-1 --cors. The requests are not shown in the http-server logs, so appear to be blocked in the browser.

Example code: example.zip