gimite / web-socket-js

HTML5 Web Socket implementation powered by Flash
BSD 3-Clause "New" or "Revised" License
2.74k stars 490 forks source link

onmessage event doesn't happens when IE8 in normal mode, but works in F12 script debug mode O_o #167

Closed Metafalica closed 8 years ago

Metafalica commented 8 years ago

No script debug mode: IE8 can send messages through websocket to server. IE8 does not receive any messages from server

If I press F12 and enable script debugging everything starting to work fine. WTF?!

rfox90 commented 8 years ago

Do you see any syntax errors or console.logs in the web console when you have the tools open.

IE8 has issues with javascript.

Metafalica commented 8 years ago

No any errors seen in log, while I even have WEB_SOCKET_DEBUG = true; Well, as soon as I turn on log everything starting to work O_o So I can't know if there is any errors in log while log is not shown.

rfox90 commented 8 years ago

Can you try adding this following code somewhere in your application:

// Avoid `console` errors in browsers that lack a console.
(function() {
    var method;
    var noop = function () {};
    var methods = [
        'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
        'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
        'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
        'timeStamp', 'trace', 'warn'
    ];
    var length = methods.length;
    var console = (window.console = window.console || {});

    while (length--) {
        method = methods[length];

        // Only stub undefined methods.
        if (!console[method]) {
            console[method] = noop;
        }
    }
}());

It stubs undefined methods of the console object. In IE 8 the console only exists when its open as far as i remember.

Metafalica commented 8 years ago

This is helped O_o Thanks for that!

gimite commented 8 years ago

You mean you used console in your own code? web_socket.js should already handle a case where console is missing.

Metafalica commented 8 years ago

Yes, I had this:

function onMessage(event)
{
    console.log(event.data); //were failing here (on first line), so I though this event never fired
    ...

It comes out that this is totally not your lib issue.

rfox90 commented 8 years ago

Which is why i asked "Do you see any syntax errors or console.logs in the web console when you have the tools open."

The snippet i provided is pretty good for general catchall solutions to IE8 issues though.