Skip to main content

Bug Tracker

Side navigation

#11229 closed bug (wontfix)

Opened January 26, 2012 11:06AM UTC

Closed January 27, 2012 01:01AM UTC

Last modified January 27, 2012 10:56AM UTC

iOS UIWebView detected as mozilla instead of webkit

Reported by: salomvary Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:
Description

jQuery loaded into iOS applications' embedded web browser view (UIWebView) detects the browser as mozilla instead of webkit. Example: links followed from Facebook app's news feed.

Expected:

$.browser.webkit === true

Got:

$.browser.webkit === undefined

$.browser.mozilla === true

UserAgent tested:

"Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_0_1 like Mac OS X; en_US) AppleWebKit (KHTML, like Gecko) Mobile [FBAN/FBForIPhone;FBAV/4.1;FBBV/4100.0;FBDV/iPhone4,1;FBMD/iPhone;FBSN/iPhone OS;FBSV/5.0.1;FBSS/2; FBCR/Carrier;FBID/phone;FBLC/en_US;FBSF/2.0]"

Attachments (0)
Change History (3)

Changed January 26, 2012 08:02PM UTC by sindresorhus comment:1

_comment0: The problem is that developers are free to [http://stackoverflow.com/questions/8487581/uiwebview-ios5-changing-user-agent change the user-agent] to whatever they want, like Facebook has done. The jQuery browser UA regex depends on the webkit version number after AppleWebKit, if it doesn't find that, it goes through the possibilities, until it stops at mozilla. Of course the regex could be split up to first try to match the webkit and then the version number, but this is not sustainable, since that is only true on the Facebook app, other apps might change the user-agent differently. The only real fix, and what people should do anyway, is to not use user-agent and instead use [http://www.modernizr.com/ feature testing].1327608404421324

The default UIWebView UA is the same as Mobile Safari except the word Safari, which would still match.

The problem is that developers are free to change the user-agent to whatever they want, like Facebook has done. The jQuery browser UA regex depends on the webkit version number after AppleWebKit, if it doesn't find that, it goes through the possibilities, until it stops at mozilla. Of course the regex could be split up to first try to match the webkit and then the version number, but this is not sustainable, since that is only true on the Facebook app, other apps might change the user-agent differently. The only real fix, and what people should do anyway, is to not use user-agent and instead use feature testing.

Changed January 27, 2012 01:01AM UTC by dmethvin comment:2

resolution: → wontfix
status: newclosed

I agree. Feature detection would definitely be your best bet. Since jQuery.browser is deprecated and this is a pretty rare situation, we aren't likely to fix it. Trying to craft a regexp in order to "fix" these situations is always hit or miss.

http://api.jquery.com/category/deprecated/

Changed January 27, 2012 10:56AM UTC by salomvary comment:3

I can confirm that this is only broken in Facebook's WebView by their modified UA string. Other apps do not seem to be affected (e.g Twitter).