False negative in History API support check on Windows Phone 8.1 #1471

gaearon opened this Issue Dec 11, 2014 · 1 comment


None yet

2 participants

gaearon commented Dec 11, 2014

Windows Phone 8.1 supports History API, but Modernizr gives a false negative.

The check in question returns false for Android 4.0 (presumably because it reports as supporting API but in fact doesn't?). However, Microsoft recently started including Android in WP user agent, leading Modernizr to believe it's an Android when in fact it's not.

Example of failing Windows Phone UA: "Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; Microsoft; Virtual) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537". As you see, it contains Android 4.0.

The fix is to add additional check for Windows Phone like I do here:

   if ((ua.indexOf('Android 2.') !== -1 ||
       (ua.indexOf('Android 4.0') !== -1)) &&
       ua.indexOf('Mobile Safari') !== -1 &&
-      ua.indexOf('Chrome') === -1) {
+      ua.indexOf('Chrome') === -1 &&
+      ua.indexOf('Windows Phone') === -1) {
     return false;
@gaearon gaearon added a commit to gaearon/Modernizr that referenced this issue Dec 11, 2014
@gaearon gaearon Update UA check to fix false negative on WP 8.1
Fixes #1471

The dark side of the UA string wars. (Okay, it’s all dark)

@patrickkettner patrickkettner pushed a commit to patrickkettner/Modernizr that referenced this issue Feb 22, 2015
@gaearon gaearon Update UA check to fix false negative on WP 8.1
Fixes #1471
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment