ai / offscreen-canvas

Polyfill for OffscreenCanvas to move Three.js/WebGL/2D canvas to Web Worker
MIT License
332 stars 13 forks source link

Safari: `Unhandled Promise Rejection: TypeError: Not enough arguments` #9

Closed jayantbh closed 4 years ago

jayantbh commented 4 years ago

On doing a worker.post({ message }), Safari throws this error. Chrome doesn't.

I think it's because postMessage expects a targetOrigin parameter to be supplied. But needs a deeper look.

image

ai commented 4 years ago

Sorry, this project is just a demo.

I will accept and release PRs, but can’t help you with issue investigation.

jayantbh commented 4 years ago

My bad. The issue was because of my own code. In the worker, I was calling postMessage with only 1 arg. The message. This worked fine on Chrome, but broke on Safari.

The fix was to just do this instead: postMessage(messageObj, window.location.origin).

So, the issue wasn't happening because of worker.post({ message }), but because of a postMessage that would be fired when the worker.post was received in the worker.

Thanks for this project. Works pretty well for me!

jayantbh commented 4 years ago

This raised a different issue. In the non-worker code, the MessageEvents for workers are never fired. That is, the listener to createWorker didn't work. But, you've mentioned that this was a demo project, so, won't file an issue for that.

Thanks for your work! :)