Featured

Supporting the SOPA/PIPA Site Blackout M

The majority of the internet community is taking a stand against SOPA/PIPA which attempts to fight copyright infringement through Internet censorship, and bypass the due process of law by allowing all

Read More
Supporting the SOPA/PIPA Site Blackout Movement

Fing-Fong-Fooey

Fing-Fong-Fooey is a game similar to Rock-Paper-Scissors, with the same purpose, to select one person in a group to be ‘it’. While Rock-Paper-Scissors (also called Ro-Sham-Bo) works with t

Read More
Fing-Fong-Fooey

Test your web browser for WebSocket supp

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

Read More
Test your web browser for WebSocket support

7 Groundrules For An Intelligent Convers

Everybody loves a great conversation. It is one of life’s simple pleasures. Sharing ideas and perspectives is a great way feel alive and connected. Looking back at the high points in your life,

Read More
7 Groundrules For An Intelligent Conversation

Adding Costco Gas Stations to Google Map

How many time have you gone to search for something on the Internet, and it just wasn’t there? Many times travelling over the last few years, I’ve wanted to know where there was a Costco g

Read More
Adding Costco Gas Stations to Google Maps

Test your web browser for WebSocket support

39
by on December 9, 2009 at 6:34 pm

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 4.0.249.0 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)");
  }
  else
  {
    // 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):

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



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. 

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

    • http://jimbergman.net Jim Bergman

      I discovered (thanks to your comment) 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

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!