Test your web browser for WebSocket support

36

Google announced an improved way for a web application to communicate with a server. The new method is called Web Sockets. You can read more info here on Web Sockets.

Here is a quick test to see if your web browser supports Web Sockets. At the time this post was published Google Chrome developer channel release 4.0.249.0 is the only browser to support Web Sockets.

Here is the JavaScript code (or right click and save file as WebSocketTest.js):

function WebSocketTest()
{
  if ("WebSocket" in window)
  {
    // Google example code
    //  var ws = new WebSocket("ws://example.com/service");
    //  ws.onopen = function()
    //  {
    //    // Web Socket is connected. You can send data by send() method
    //    ws.send("message to send"); ....
    //  };
    //  ws.onmessage = function (evt) { var received_msg = evt.data; ... };
    //  ws.onclose = function() { // websocket is closed. };
    alert("WebSockets supported here!rnrnBrowser: " + navigator.appName + " " + navigator.appVersion + "rnrntest by jimbergman.net (based on Google sample code)");
  }
  else
  {
    // the browser doesn't support WebSockets
    alert("WebSockets NOT supported here!rnrnBrowser: " + navigator.appName + " " + navigator.appVersion + "rnrntest by jimbergman.net (based on Google sample code)");
  }
}

Sample HTML code (save file as WebSocketTest.html in same folder as .js file above):

<html>
<head>
<title>JimBergman.net - JavaScript: WebSocketTest</title>
<script type="text/javascript" src="WebSocketTest.js"></script>
</head>
<body bgcolor="#FFFFFF">
<a href="javascript:WebSocketTest()">Run WebSocket test</a>
</body>
</html>



UPDATE:

Result of this test on an Windows 7 PC in Google Chrome v4.0.249.0


Result of this test on an Windows 7 PC in Mozilla Firefox v3.5.5


Result of this test on an Windows 7 PC in Microsoft Internet Explorer v8.0.7100.0


Result of this test on an Apple iPhone in OS 3.1.2

Creative Commons License
Test your web browser for WebSocket support by Jim Bergman is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Permissions beyond the scope of this license may be available at http://jimbergman.net/about.

  • Pingback: Tweets that mention JimBergman.net » Test your web browser for WebSocket support -- Topsy.com

  • http://profiles.yahoo.com/u/HIMSKX7IIFCFP36SAYHTKVKQ4Y kefka_the_cruel

    Works in WebKit nightly builds as well.

  • http://jimbergman.net Jim Bergman

    Thanks for the additional info. That means in the future Web Socket support should be in Safari on the desktop, and the iPhone and Android mobile browsers, as those are all based on WebKit.

    A full list of WebKit-based browsers is on Wikipedia

  • Pingback: links for 2010-01-28 « sySolution

  • http://tech.element77.com/ Arun

    Safari on iPhone OS 4.0 (build 8A230m) claims to support WebSocket.

  • http://jimbergman.net Jim Bergman

    That is confirmed with iPhone OS 4 beta 2. I assume once the iPad goes to OS 4 it will support WebSocket as well.

    Thanks for checking that out Arun!

  • http://www.opensoruceconnections.com Eric Pugh

    I am using Safari 4.0.5 on Snow Leopard and websockets work (tested via using PusherApp.com), but this script reports that it doesn't work… Chrome did report back that it worked. I am looking for some JS that would check if websocket support was enabled.

  • Pingback: Firefox 4 gets web sockets support • Mozilla Links

  • Paul Leman

    works in Mac Safari Version 5.0 (6533.16)

  • Pingback: [Brève] Firefox 4.0 supporte les Web Sockets - Websourcing.fr

  • Sam Lalani

    I downloaded iOS 4 on my iPhone 3GS and when I go to this page on it, it says “WebSocket NOT supported here!”.

  • http://tech.element77.com Nobody

    With the final iOS 4.0 release, Apple seems to have removed WebSocket support from Safari.

  • John22

    Bzzt. Sigh.

  • Pinetree

    firefox 3.7 alpha 6 – finally supports websockets and is doing fine – get it here http://nightly.mozilla.org/

  • http://www.facebook.com/people/Chris-OBrien/27205858 Chris O'Brien

    You could also type this in your browser's address bar instead of a URL:

    javascript:alert(“WebSockets are ” + (window.WebSocket ? “” : “not “) + “supported”);

  • http://jimbergman.net Jim Bergman

    Works great! Thanks!

  • Pingback: Firefox 4 con soporte para Web Sockets « Mozilla Links en español

  • Mr. Socket

    To note, just because the browser finds the object doesn't mean it's actually implemented. Chrome 6 and Firefox 4b2 both show false positives. To see if your browser can actually use websockets you might want to check: http://html5demos.com/web-socket

  • http://jimbergman.net Jim Bergman

    The html4demo web-socket test is a nice chat app that run via sockets using ws:// and includes source code. Works in Chrome 5.0.375.99, but not in Firefox 3.6.6 or IE8. Thanks for the link and info!

  • Rsanchez1990

    I like this method. It's better to have a concrete test for functionality, and it works on Chrome on Ubuntu.

  • Rsanchez1990

    I like this method. It’s better to have a concrete test for functionality, and it works on Chrome on Ubuntu.

  • Pingback: Quora

  • Fff

    Opera 10.70 snapshot supports the latest websockets spec as of today.rnrn

  • witek

    Works in Opera 10.70 – today’s update :) rn

  • JohnDoe

    Works fine in rekonq 0.6.1 , KDE4 web browser based on Webkit

  • Sam Lalani

    I installed iOS 4.2 on my iPad and it says it supports WebSockets!!

  • Pingback: *drawlogic » WebSockets Now Available Across iOS Devices with 4.2 Update *drawlogic

  • http://twitter.com/viviangledhill Vivian Gledhill

    check out the new update: http://img4web.com/view/CU53HX (iOS v4.21 screencap)

  • Pingback: Web Socket和HTML5发展近况 « Notor Blog | notor.me

  • Pingback: » Web Socket和HTML5发展近况 NoTor

  • Adailton Moraes

    IE9 not supported #FAIL

  • teox

    The button to test websockets does nothing when I click it. It doesn’t even show a hand cursor when you mouse-over it. The html in this page seems to be broken; there is a twitter bar in the upper right part of the page, clearly out of place.

    However this same post is visible in the home page at http://jimbergman.net/ and there it works.

    Latest Firefox on Ubuntu.

    • http://jimbergman.net Jim Bergman

      Hmmm. I’m seeing the same thing in Firefox on Win 7 and Win XP. Works fine in Chrome and IE8. Looks like it is caused by the Disqus commenting system. Using Firebug, if I delete the div id=”dsq-content” from the page, it works fine. That div isn’t rendering the same on Firefox as other browsers. Will check into it further. Thanks for the heads up.

    • http://jimbergman.net Jim Bergman

      Found a CSS fix on the Disqus website at http://docs.disqus.com/help/69/

  • http://twitter.com/powtac Simon Brüchner

    No Websocket support in Firefox 4.0.1 on OS X. 

My iOS & Android Apps

Elsewhere on the web

Jim's book recommendations, favorite quotes, book clubs, book trivia, book lists (read shelf)

Like this page?

Popular Posts


FreshBooks



SPECIAL Offer! Save 20% off all New Hosting Plans!