Thursday, January 10, 2013

Get WebGL working on the Android Chrome Beta

[UPDATE: This whole process just got a lot easier! With the newest update you can now visit about:flags (or chrome://flags, take your pick) and click the link that says "Enable WebGL". Then restart the browser and you're done! Best of all? No root required!]

Today a new Chrome Beta was released to the Google Play store. While the current stable Chrome release is based on the relatively old and crusty Chrome 18, the beta is based on the Chrome 25 code base. It's a big step forward in a lot of aspects, but there's one very specific capability that was added that's of interest to readers of this blog: WebGL support!

Now don't get too excited, because it's not turned on out of the box and not everyone will be able to enable it, but if you're interested in doing some early testing of your WebGL app(s) it's now possible with a little bit of tinkering.

Here's what you'll need:
  • A rooted Android device running Jellybean or Ice Cream Sandwich. This will be the biggest hurdle for many people, as rooting can be complicated depending on your device. I'm not going to go into how to root your device here, that's what Google is for.
  • A Windows, Mac, or Linux computer
  • The Android SDK for your OS of choice. Make sure you've installed the Platform Tools, we need adb.
Once you've got all of that actual process of enabling WebGL is pretty simple. Plug your Android device in to the computer with a USB cable, then open up a console/terminal instance and enter this:

adb shell 'echo "chrome --enable-webgl" > /data/local/chrome-command-line'


Now when you launch the Chrome Beta, WebGL will be enabled! Go give it a try with your favorite demos. Please keep in mind that there's a reason it's not enabled by default, this IS a beta release, after all!z Don't be surprised if the browser crashes while you get your WebGL on. It's stable enough to do testing and development, though, and if you DO encounter issues bug reports are appreciated!

Update: Added a video about the process and showing a couple of quick demos



Update #2: So a lot of people have (justifiably) been annoyed at the requirement for root to enable this and are wondering why we can't just have an about:flags page like the desktop. A couple of comments regarding that:
  • Obviously this method isn't terribly user friendly. It's not intended to be a final solution. I've heard from our Developer Relations people that a more robust, accesible solution is on the way but I don't have any timeline for that. The information in this post is intended to be a way for developers to get early access to the feature for testing.
  • If the file in question was not in a protected directory it would be very easy for malicious Android apps to hijack your browser and force it to do undesirable things. The root requirement is to protect the user in this case. Annoying, but necessary.
Please don't think anybody on the Chrome for Android team things that mucking about in adb is an acceptable user experience. "User Friendly" takes time, though, and there's a certain class of enthusiasts (like myself) who are willing to endure a bit of awkwardness to get features as early as possible. That's who this post was intended for.