Trying out the web worker API for the first time and can't seem to get a response from the background worker.
Markup:
<script src="~/Scripts/script.js"></script>
<button onclick="TriggerWorker()">Trigger Worker</button>
Contents of script.js file:
function TriggerWorker() {
var myWorker = new Worker('worker.js');
myWorker.onmessage = function (e) {
console.log(e.data);
}
console.log(myWorker);
myWorker.postMessage("Text sent to worker");
}
Contents of worker.js file:
onmessage = function (e) {
postMessage('OK');
}
I can get the myWorker object to write to the console, but the response "OK" never makes it back into the console. When inspecting the myWorker object, I can see that the onmessage property is set to "Permission denied".