HTML and CSS Reference
In-Depth Information
There are several ways to determine whether your own browser supports WebSocket.
One handy tool to use to investigate your code is the web browser's JavaScript console.
Each browser has a different way to initiate the JavaScript console. In Google Chrome, for
example, you can open the console by choosing View Developer Developer Tools ,
then clicking Console . For more information about Chrome Developer Tools,
see .
Google's Chrome Developer Tools also enables you to inspect WebSocket
traffic. To do so, in the Developer Tools panel, click Network, then at the bottom of the panel,
click WebSockets. Appendix A covers useful WebSocket debugging tools in detail.
Pro Tip
Open your browser's interactive JavaScript console and evaluate the expression
window.WebSocket . If you see the WebSocket constructor object, this means your web
browser supports WebSocket natively. If your browser supports WebSocket but your
sample code does not work, you'll need to further debug your code. If you evaluate the
same expression and it comes back blank or undefined, your browser does not support
WebSocket natively.
To ensure your WebSocket application works in browsers that do not support
WebSocket, you'll need to look at fallback or emulation strategies. You can write this
yourself (which is very complex), use a polyfill (a JavaScript library that replicates
the standard API for older browsers), or use a WebSocket vendor like Kaazing, which
supports WebSocket emulation that enables any browser (back to Microsoft Internet
Explorer 6) to support the HTML5 WebSocket standard APIs. We'll discuss these options
further in Chapter 8 as part of deploying your WebSocket application to the enterprise.
As part of your application, you can add a conditional check for WebSocket support,
as shown in Listing 2-19.
Listing 2-19. Client Code to Determine WebSocket Support in a Browser
if (window.WebSocket){
console.log("This browser supports WebSocket!");
} else {
console.log("This browser does not support WebSocket.");
There are many online resources that describe HTML5 and WebSocket compatibility
with browsers, including mobile browsers. Two such resources are
and .
Search WWH ::

Custom Search