Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

history check for version of Android 4.0.x aswell #891

Closed
wants to merge 1 commit into from

Conversation

pierrickchabi
Copy link

Modernizr.history returns a false positive with Android 4.0.4 stock browser.
This fixes it for Android 4.0.x more generally.

Main reasons why I track all 4.0.x versions here is:
Many people noticed Android 4.0.x stock browser is not fully supporting history.
More specifically, the address bar is not correctly updated.

StackOverflow:
http://stackoverflow.com/questions/10620843/pushstate-in-android-4-0.

Android project issues reports :
https://code.google.com/p/android/issues/detail?id=17471
https://code.google.com/p/android/issues/detail?id=23979

@stucox
Copy link
Member

stucox commented Apr 9, 2013

According to issue 23979, this is still a problem in the Android 4.1.x native browser (Chrome's the default browser on this version, but the native one is often still installed).

It'd be good to capture this too. The check's getting a bit unreadable though! Maybe it's regex time?

if (/Android (2\.2|2\.3|4\.0|4\.1).* Mobile Safari/.test(ua) && ua.indexOf('Chrome') === -1) {
  return false;
}

@jokeyrhyme
Copy link
Contributor

Is there a way to programmatically detect a faulty History implementation without resorting to browser user agent sniffing?

@stucox
Copy link
Member

stucox commented Apr 16, 2013

@jokeyrhyme — Here's the original discussion on this: #733... general consensus was that it would be hard to detect (certainly smoothly), but very happy to try and improve this if we can think of a way.

This seems to cover versions which don't update location.pathname (e.g. Android 2.3):

Modernizr.addTest('history', function () {
  var oldLoc = window.location.toString();
  var result = false;

  if (window.history && 'replaceState' in window.history) {
    // Try changing history
    window.history.replaceState({}, '', oldLoc + 'a');
    result = window.location.toString() === oldLoc + 'a';

    // Put it back how we found it
    window.history.replaceState({}, '', oldLoc);
  }
  return result
});

But on 4.0.x and 4.1.x (maybe others too), the location object is updated correctly but the address bar isn't until refreshed. I have no idea how we can detect this without a UA sniff.

Interestingly, on 4.1.2 at least, the address bar is updated correctly if pushState() / replaceState() is called during page load — it works in a synchronous inline script, but doesn't on e.g. a click handler.

@toebu
Copy link

toebu commented Jan 8, 2014

This snif has been broken for quite a while, any chance to get this merged? One should also add the sniff for Android 4.1 since it's still broken there. It works on Chrome on Android though, so it should be a bit more specific.
I don't like the test from @stucox, seems a bit risky to go modify the history, especially since we know it's buggy.

I can make a new PR with those changed ua sniffs, if it's gonna get merged :)

@patrickkettner
Copy link
Member

It has to be updated since it can't be merged as is. There are a couple other broken tests that need to be backported. Once this is updated, we'll probably ship another minor version

@toebu
Copy link

toebu commented Jan 8, 2014

So should I make a new PR against master?

@patrickkettner
Copy link
Member

I can whip it up, but in general that is what needs to happen, yes.

@jokeyrhyme
Copy link
Contributor

The current thinking regarding user agent sniffing is that we should use feature detection to enable behaviours, and that it is acceptable to use user agent sniffing to disable behaviours. Obviously, we'd all love to live in a world where feature detection is all we need, but sometimes our only option is to explicitly blacklist specific browsers.

stucox pushed a commit that referenced this pull request Mar 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants