Using Safari to mimic the iPhone browser

Ever wanted to access an iPhone-only site like iphone.beejive.com? Not surprisingly, I couldn't get JiveTalk for the iPhone to work in Firefox (using an iPhone user-agent string), but it worked fine in Safari. I tested this with Safari 2.0.4 and Safari 3.0.2 on OS X 10.4.10 and it worked fine, but Safari 3.0.2 on Windows seems to ignore the CustomUserAgent parameter. In other words this only works on a Mac.

Make sure you have an iPhone user agent handy, like this one:

Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A538b Safari/419.3
  1. First, quit Safari if it's running.
  2. If you haven't done so already, enable the Safari debug menu, this will let you change your user agent back easily and give you some other useful options.
  3. On a Mac1 open a new terminal and type:
    defaults write com.apple.Safari IncludeDebugMenu 1
  4. Next you'll set the CustomUserAgent key to change the Safari user agent. From the same terminal window type:
    defaults write com.apple.Safari CustomUserAgent '"Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A538b Safari/419.3"'
  5. Use this bookmarklet to resize the viewport to 320 x 396:
    javascript:void(window.resizeTo(self.outerWidth-self.innerWidth+320,self.outerHeight-self.innerHeight+396))
  6. Browse to http://iphone.beejive.com/ or some other iPhone-only site
    Note: If you don't have a vertical scrollbar the first time you run the bookmarklet, and then one is displayed it'll create a horizontal scrollbar which messes up the display.
  7. When you're ready to switch back to the default user agent just open the Debug menu and select User Agent > Automatically Chosen.

JiveTalk for the iPhone - Accounts JiveTalk for the iPhone - Google Talk

  1. To enable the Safari Debug menu on Windows see my earlier post [back]

 

6 Responses to “Using Safari to mimic the iPhone browser”

  1. crawlspace|media Says:

    [...] Using Safari to mimic the iPhone browser | corey gilmore's blog (tags: iphone development iphoneapp code mac osx safari) [...]

  2. Jared Says:

    Hey Corey, nice little bit of code, works a treat. Question for you though, how do you reverse step 4?

    Thanks

  3. UG Says:

    To reverse step 4 I wrote:
    defaults write com.apple.Safari CustomUserAgent '""'
    It worked fine…

  4. Corey Says:

    You can also use

    defaults delete com.apple.Safari CustomUserAgent

    to remove the key.

  5. ksama Says:

    has anyone tried this on windows and actually got it working? I have safari for windows (v.5.0) running on Windows 7. so I located the "com.apple.Safari.plist" file from C:\Users\\AppData\Roaming\Apple Computer\Preferences directory and added the follwoing entry.
    CustomUserAgent
    Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A538b Safari/419.3

    when I open safari back it seems to default back even if the Developer menu is disabled. Through the plist file it takes the changes I make like hide/show developmer menu etc. but seems ignor the CustomUserAgent. Is this a known issue or off any work arround???

  6. James Says:

    Never even thought to try and look at it from the iphone view.

Leave a Reply


© 2007-2013, Corey Gilmore | Posts RSS Feed | Comments RSS Feed | Contact

 

The views expressed on these pages are mine alone and not those of any past or present employer. All information presented on this site was obtained lawfully and not through disclosure under the terms of an NDA.