Test your web browser for WebSocket support

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

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

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()
    //  {
    //    // WebSocket 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!\r\n\r\nBrowser: " + navigator.userAgent + "\r\n\r\ntest by jimbergman.net (based on Google sample code)");
    // the browser doesn't support WebSockets
    alert("WebSockets NOT supported here!\r\n\r\nBrowser: " + navigator.userAgent + "\r\n\r\ntest by jimbergman.net (based on Google sample code)");

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

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

You can find more information on WebSocket at the Mozilla Developer Network.

UPDATE May 4th, 2012:

Updated to report browser data using navigator.userAgent.
The previous version of this script used browser data from navigator.appName and navigator.appVersion, which are not consistent in different browsers (mainly Firefox).


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.

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

  • Works in WebKit nightly builds as well.

  • 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()

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

  • 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!

  • 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!”.

  • 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/

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

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

  • 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

  • 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()

  • 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.

    • 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.

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

  • No Websocket support in Firefox 4.0.1 on OS X. 

  • Pingback: Install Firefox for Android in the ICS (4.0) emulator | Devendra @ Work()

  • Shoreas

    Works in Firefox 11.0 under Vista, although the test misreports the browser as Browser: Netscape 5.0 (Windows)

    • Thanks to your comment, I discovered that Firefox doesn’t report the same information via navigator.appName and navigator.appVersion that other browsers do. I changed the script to use navigator.userAgent instead, so now Firefox displays the same information as other browsers. Thanks for pointing out the discrepancy. Reference: http://www.javascriptkit.com/javatutors/navigator.shtml

  • Pingback: Leo Blog » The art of Testing()

  • This, however, doesn’t detect if WebSocket is supported on Firefox, since it’s named MozWebSocket over there…

    • FireFox doesn’t let you type javascript: bookmarklets in the address bar anymore. If you want to use a bookmarklet you have to save it to your saved bookmarks. This is a security feature in FireFox.

      If you save the bookmarklet above in FireFox, it detects WebSocket just fine.