I don't think the onmessage listener works for events that do not originate on your computer--it is for mouse/keyboard events. I always use the addEventListener for the event name or prefix. As a bonus you can add listeners for the opened and error events too.
There are bunch of tutorials but this one is the easiest: