- Code: Select all
var worker = new SharedWorker('shared-worker.js');
worker.port.start();
worker.port.onmessage = function(e) {
console.log('Main thread received a message from shared worker ', e);
}
worker.onerror = function(e) {
console.log(e);
}
function pingShared(){
console.log('Pinging shared worker..');
worker.port.postMessage('ping');
}
I need to add Authentication and other headers to the get request to obtain the "shared-worker.js" script requested in the first line above.
I have included the required logic in the BrowserResourceRequestHandler::OnBeforeResourceLoad function, but the control never reaches this function after the constructor tries to create the shared worker and get the script.
Hence, the request goes out without auth headers and server responds with a 401. But I checked the same logic using a regular dedicated worker using a WebWorker() constructor, where the control reaches the mentioned function, headers are getting added and the script is obtained correctly.
Any idea why this is happening or if I should treat SharedWorker script requests in a different manner?