jnordberg / gif.js

JavaScript GIF encoding library
http://jnordberg.github.io/gif.js/
MIT License
4.76k stars 668 forks source link

Side effects with other scripts using postmessage #32

Closed lyncee closed 10 years ago

lyncee commented 10 years ago

Hello,

I just figured out that in some points, when there is an other plugin in the page using postmessage, it has some side effects with gifjs.

I have in my page a youtube html5 player, and when gifjs is also loaded (whatever the loading order), I got this error:

Uncaught SyntaxError: Failed to execute 'postMessage' on 'Window': Invalid target origin '' in a call to 'postMessage'. GIFEncoder.js:55

I will check with some other scripts using postmessage if it does the same side effects anyway and keep you updated if I find a workaround.

Cheers guys, thank you for this awesome work.

hero4th commented 10 years ago

Same problem here, I tried debbuging it with chrome and found this

postmessage_error

I really don´t know how 'postMessage' work, but the bug is from the TypedNeuQuant.js file that is called. Line 431 module.exports = NeuQuant;

Any help will appreciated.

Great work from Johan Nordberg, thank you

keithamus commented 10 years ago

It looks like you might be loading gif.worker.js (or gif.worker.coffee) in your HTML. It is not meant to be loaded by you - only by gif.coffee. Remove the reference to it, so that it is only loaded when a new worker is spun up.

By including gif.worker.js - which does self.onmessage, it is actually doing window.onmessage - at which point it receives all messages from all workers, and tries to render a frame from those messages - meaning any worker (that isn't a gif worker) that sends a message will cause this error to throw.

lyncee commented 10 years ago

Hello Keithanus !

Thank you for the trick, it did it.

My bad I feel a bit stupid. Thank you for your follow up !

keithamus commented 10 years ago

@lyncee no problem! You should close this issue.

hero4th commented 10 years ago

Same here, thank you!