Sam Rayner

Hi, I’m Sam. I design and build apps for iOS and the web. I live in Sheffield, UK and play Ultimate far too much. You can reach me via email or on Twitter.

Wanted - User Agent Spoof Safari Extension

Since uninstalling Flash on my Mac I’ve found it frustrating following links to video and audio websites that require it. YouTube, SoundCloud, TED and CollegeHumor (to name a few) all offer HTML5 players to mobile devices but force a Flash player on desktop visitors.

To get around it, I either use my Open in Chrome Applescript or this Applescript to spoof the user agent string. To use it, you’ll first need to enable the Develop menu in Safari preferences > Advanced and enable access for assistive devices in System Preferences > Accessibility.

tell application "Safari" to activate
tell application "System Events"
  click menu item "Safari iOS 5.1 — iPad" of ((process "Safari")'s (menu bar 1)'s (menu bar item "Develop")'s (menu "Develop")'s (menu item "User Agent")'s (menu "User Agent"))
end tell

The script works well, reloading the current tab complete with working player, but it feels like something that could be automated.

What I would love is a Safari extension that takes a list of domains and automatically spoofs the user agent string or at least redirects to the mobile version on visiting them. Unfortunately, being JavaScript-based, I’m not sure the former is possible with a Safari extension but the (slightly more limited) latter solution might be.

If anyone has any ideas on getting this done, please give me a shout on Twitter @samrayner! Hopefully, eventually, such a script won’t be necessary and sites like YouTube will do a better job falling back to HTML5.

Update (Sep 12): Looks like I’m not the only one who wants this.

Unfortunately, it turns out most of the offending websites rely solely on the user agent to serve HTML5 media. doesn’t always exist and, when it does, often behaves differently when viewed with a desktop user agent. Fellow developers – please use object detection not UA detection.

It looks like a Safari extension is out of reach, but a Chrome extension already exists thanks to a recent update to the Chrome Extensions API. Hopefully Apple will follow suit.

Post Archive