SocketJS on IE9 only works when Developer Tools (F12) was opened

387 views
Skip to first unread message

ddew...@gmail.com

unread,
Jul 25, 2014, 5:36:49 AM7/25/14
to soc...@googlegroups.com
Hi,

After following the Spring Websocket guide on http://spring.io/guides/gs/messaging-stomp-websocket/ I noticed the following behavior on IE9

1. When I launch an IE9 brower without the Develop Tools opened (F12) and go to the app the websocket doesn't work.
2. When I launch an IE9 browser with the Develop Tools opened (F12) and go to the app the websocket does work.

In order to debug the issue I added some alerts and indeed notice that in the first case the connect works but it never receives msgs.
In the second case with the dev tools opened everything works fine.
The dev tools open in Browser mode : IE9  Document mode : IE9 standards

Here's the javascript.

        function connect() {
            var socket = new SockJS('/hello');
            stompClient = Stomp.over(socket);            
            stompClient.connect({}, function(frame) {
            alert("connected : "+ frame);
                setConnected(true);
                console.log('Connected: ' + frame);
                stompClient.subscribe('/topic/greetings', function(greeting){
                alert("msg received");
                    showGreeting(JSON.parse(greeting.body).content);
                });
            });
        }

Any ideas why it is behaving this way and any pointers on howto debug this? 

Thanks...

Niklas Bivald

unread,
Jul 28, 2014, 10:14:42 AM7/28/14
to ddew...@gmail.com, soc...@googlegroups.com
Hi,

What is the error message? It sounds like the IE9 console.log problem. Luckily if this is the bug in play any number of hacks work, including the one below. 

I'll let Stack Overflow answer:

In Internet Explorer 9 (and 8), the console object is only exposed when the developer tools are opened for a particular tab. If you hide the developer tools window for that tab, the console object remains exposed for each page you navigate to. If you open a new tab, you must also open the developer tools for that tab in order for the console object to be exposed.

The console object is not part of any standard and is an extension to the Document Object Model. Like other DOM objects, it is considered a host object and is not required to inherit from Object, nor its methods from Function, like native ECMAScript functions and objects do. This is the reason apply and call are undefined on those methods. In IE 9, most DOM objects were improved to inherit from native ECMAScript types. As the developer tools are considered an extension to IE (albeit, a built-in extension), they clearly didn't receive the same improvements as the rest of the DOM.

For what it's worth, you can still use some Function.prototype methods on console methods with a little bind() magic:

var log = Function.prototype.bind.call(console.log, console);

log
.apply(console, ["this", "is", "a", "test"]);
//-> "thisisatest"


--
You received this message because you are subscribed to the Google Groups "sockjs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sockjs+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages