SzilardD
SzilardD

Reputation: 1751

HTML5 web worker error "Uncaught SyntaxError: Not enough arguments" when using multiple postMessage calls

I have a single web worker which makes about 30 AJAX requests and after each request it sends a message to the UI using postMessage to log the progress. For example:

postMessage({type: "progress", name: "customers", message: "Success" }).

After about 10-20 requests (not always the same number), the following error appears:

Uncaught SyntaxError: Not enough arguments.

If I remove the postMessage calls, everything works fine, and if I add additional postMessage calls, the web worker gives the error after even fewer requests.

It seems to also depend on the type of data, the web worker dies sooner if the postMessage calls contain JSON objects rather than strings.

Does anyone know why this happens ?

Upvotes: 0

Views: 934

Answers (1)

SzilardD
SzilardD

Reputation: 1751

It turns out that, at least in my case, postMessage fails if it is called multiple times in a short amount of time (milliseconds)

Calling postMessage only every 500 milliseconds solved the issue for me.

Upvotes: 0

Related Questions