2

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?

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

1 Comment

A fix for this has made it into Safari Technology Preview at the time of this comment.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.