Home > Articles > Home & Office Computing > The Web/Virtual Worlds/Social Networking

  • Print
  • + Share This
Like this article? We recommend Testing HTML5 Features

Testing HTML5 Features

I previously suggested starting up a more recent version of Firefox or Chrome to try out the FileAPIDemo application. I did not suggest starting up Safari or Opera because this application doesn't work with these browsers. Because support for HTML5 features varies from browser to browser, you should test how well browsers support these features before deploying feature-dependent HTML5 applications.

In the following sections, I test browser support for the HTML5 audio, canvas, and File API features. The browsers I'm using to perform these tests are Chrome 6.0.472.63, Firefox 3.6.10, Firefox 4.0 Beta 6, Opera 10.63, and Safari 5.0.2. I'm not testing with Internet Explorer because version 8 is extremely limited in its HTML5 support, and version 9 doesn't support my Windows XP platform.


I began to test browser support for the HTML5 audio feature by running AudioDemo.html in each of the previously mentioned browsers. Only the Chrome and Safari browsers were able to play the referenced 111491075.mp3 file.

I subsequently converted 111491075.mp3 to an equivalent 111491075.ogg file by using an online OGG converter tool. I discovered that Chrome, both Firefox versions, and Opera could play 111491075.ogg.

I next focused on trying to play 111491075.mp3 or 111491075.ogg via the DOM's Audio API; for example, var audio = new Audio("file://c:/temp/111491075.mp3"); audio.play();. I was able to use this API to play the MP3 or OGG file as determined by the browser.

I did not perform additional audio element/API tests (such as determining preloading support) because I found the previous tests sufficient for designing the audio portion of the HTML5 application that I present in Part 2. Accordingly, it must play an MP3 file under Safari, an OGG file under all other browsers except for Chrome, and an MP3 or OGG file under Chrome.


HTML5's canvas feature originated as an Apple creation and is probably the most widely supported of all HTML5 features. When I tested a simple canvas on the aforementioned browsers, I was able to observe the same graphics on each browser.

The canvas feature's API evolved over time and this API's text functions (such as fillText()) were not initially supported. To determine if a browser supports these functions, it's sufficient to check for the presence of fillText() via typeof context.fillText == 'function', which returns true when this function is supported. This expression returned true for all of the aforementioned browsers.

File API

Unlike the audio and canvas elements, there is much less consistent support for the File API. The first of my File API tests examined file chooser activation and support for the FileList interface. Of the various browsers, only Opera failed this test, as follows:

  • Opera does not support the <input> tag's multiple attribute, which means that only a single file can be selected.
  • More seriously, Opera does not support FileList and a files property, so there is no way to obtain the selected file. In FileAPIDemo, files = document.getElementById("files list").files; results in the files variable containing the undefined value, and a subsequent attempt to evaluate files.length results in the following error message: Uncaught exception: TypeError: Cannot convert 'files' to object.

I also encountered a strange anomaly when testing the file chooser under Safari. When the file chooser appears over a link, and when the mouse cursor is moved over that part of the file chooser that sits above the link, the mouse cursor changes from a pointer to a hand, even when the mouse cursor is over a filename.

If I press a mouse button, the link is activated; the file is not selected. The (awkward) solution is to drag the file chooser dialog to a portion of the browser where no links appear (or even off of the browser window). I've observed this anomaly with the Windows XP version of Safari; it might not occur with the Apple version.

My second test involved determining whether or not the FileReader interface is supported. I discovered that Safari and Opera do not support this interface. In contrast, the other browsers support FileReader. (Firefox presents an expanded File interface with alternative file-reading methods such as getAsDataURL(). FileReader replaces these methods.)

My final test involved determining whether or not the Blob interface is supported. Blob lets you read a smaller section of a file, instead of having to read the entire file's contents. For example, where fr.readAsBinaryString(files[i]); reads the entire content, fr.readAsBinaryString(files[i].slice(0, 128)); reads no more than the first 128 bytes. I found that only Chrome supports Blob.

  • + Share This
  • 🔖 Save To Your Account