Reputation: 47
I use a Web Worker in my JavaScript code, the class in which I use the Worker looks as follows:
class EnemyMoveCalculater {
constructor() {
this.worker = null;
}
startMoveCalculation(boardData, nextPlayer, jokerReady, enemyMoveHandlerCallback) {
this.worker = new Worker('js/calculateEnemyMoves.js');
this.worker.onmessage = function(e) {
this.worker.terminate();
this.worker = null;
enemyMoveHandlerCallback(e.data);
}.bind(this);
this.worker.postMessage([boardData, nextPlayer, jokerReady]);
}
terminateMoveCalculation() {
if (this.worker) this.worker.terminate();
}
}
My Website is working in Firefox (for Windows and Android), Edge and Samsung Internet Browser. However, when the "startMoveCalculation" runs in Safari (Version 12.1.2) I get the following Error:
ReferenceError: Can't find variable: Worker
What could be the problem?
Upvotes: 2
Views: 2465
Reputation: 166
Safari unfortunately as of now does not support spawning Web Workers from inside other Web Workers. The Worker may have to request the main thread to spawn another worker and manage communication between workers in this case.
Chrome seems to have Safari / WebKit down as "No Signal" of shipping this feature:
https://www.chromestatus.com/feature/6080438103703552
WebKit bug to follow:
https://bugs.webkit.org/show_bug.cgi?id=25212
Upvotes: 5