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

Augment userAgent detection #470

Closed
wants to merge 4 commits into from

Conversation

gkatsev
Copy link
Member

@gkatsev gkatsev commented Apr 26, 2013

Add a userAgent detection for Chrome.
Rework detection using RegExp#test to make the checks more efficient.
Make the vjs.IS_ANDROID just check for android so that it can be used in conjunction with the firefox and chrome checks.
Fix vjs.IS_FIREFOX being a function that is used as a property by making it be a property like the other predicates.

@@ -314,7 +314,7 @@ vjs.IOS_VERSION = (function(){
if (match && match[1]) { return match[1]; }
})();

vjs.IS_ANDROID = !!vjs.USER_AGENT.match(/Android.*AppleWebKit/i);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only one that worries me, because we currently use the webkit check to make sure we only override the canPlayType function in the default android browser. Changing this would match Firefox too. We just need a solution that takes that into consideration.
https://github.com/videojs/video.js/blob/master/src/js/media/html5.js#L231

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That if statement also checks the version of android. Firefox does not report the version of android; only Chrome for Android and the Native Android browser do. So, we could add a check there to make sure the version isn't null, since null < 3 is true.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, why are we check if the version is less than 3 if it is only broken on 2.2 and lower?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming it's still broken in 2.3 and fixed in 3.

On May 6, 2013, at 3:59 PM, Gary Katsevman [email protected] wrote:

In src/js/lib.js:

@@ -314,7 +314,7 @@ vjs.IOS_VERSION = (function(){
if (match && match[1]) { return match[1]; }
})();

-vjs.IS_ANDROID = !!vjs.USER_AGENT.match(/Android.*AppleWebKit/i);
By the way, why are we check if the version is less than 3 if it is only broken on 2.2 and lower?


Reply to this email directly or view it on GitHub.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, just the comment and code are in disagreement. I can do a quick check and see anyway.
Do you think that checking for null there is a good compromise?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it does say 2.2. Definitely worth checking then.

Checking for null how?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in media/html5.js, do a null check before checking the version, since firefox doesn't report report android version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that's interesting. I didn't realize Firefox didn't report Android version. Is that true for other browsers like opera mobile too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to http://www.useragentstring.com/pages/Opera Mobile/, some versions do report the android version and some don't. I'll do a quick check on that as well.
Checking for webkit in the long run, isn't a good idea, since chrome is moving to Blink at some point. We might want to have a separate check for webkit or something else for older androids.

@gkatsev
Copy link
Member Author

gkatsev commented May 7, 2013

Taking the convo out of line-notes.
Android 2.3 does report the canPlayType correctly for video/mp4 and does new version of Firefox on Android 4.2. Firefox on Android 2.2 does not report canPlayType correctly (could also not be able to play, haven't check yet).

@gkatsev
Copy link
Member Author

gkatsev commented May 7, 2013

Opera does return the android version in the userAgent. However, it's return value for canPlayType is probably.
Firefox does not return the android version and has similar problems to native android browser with the return value of canPlayType.
Android 2.3 did fix the canPlayType issue, so, we should change the version number check to be < 2.3.
For future proofing, we should remove the webkit check from vjs.IS_ANDROID, what we should do instead, especially considering the canPlayType issue, I'm not sure. One suggestion I have is to add a vjs.IS_WEBKIT and then we can check

if (vjs.IS_ANDROID && vjs.IS_WEBKIT && vjs.ANDROID_VERSION < 2.3) {
  /* apply canPlayType fix */ 
}

I can't think of any other or better ways at the moment.

@heff
Copy link
Member

heff commented May 8, 2013

Ok, thanks for doing all that research. What if we wrapped those 3 checks into an 'oldAndroid' check. I'm looking at a presentation I did and I had 3 major bugs listed:

  • No touch to start
  • Type attributes breaks playback
  • canPlayType broken
    All of those were fixed as of v2.3. How does something like vjs.IS_OLD_ANDROID sound?

I like what you said earlier about only using user agent checks for older browsers. Having a vis.IS_WEBKIT might open the door for people to use that in places they shouldn't.

@gkatsev
Copy link
Member Author

gkatsev commented May 8, 2013

vjs.IS_OLD_ANDROID would be android, webkit, and version < 2.3?
I think that is acceptable.

@heff
Copy link
Member

heff commented May 8, 2013

Cool, that works for me.

On May 8, 2013, at 3:29 PM, Gary Katsevman [email protected] wrote:

vjs.IS_OLD_ANDROID would be android, webkit, and version < 2.3?
I think that is acceptable.


Reply to this email directly or view it on GitHub.

@gkatsev
Copy link
Member Author

gkatsev commented May 8, 2013

Ok, i'll make that change in a bit.

@gkatsev
Copy link
Member Author

gkatsev commented May 8, 2013

Looks like vjs.ANDROID_VERSION was only ever catching the major version of android (i.e., 4 from 4.2.1).
This is why the check is for vjs.ANDROID_VERSION < 3.
Looks like the only check for vjs.ANDROID_VERSION is in the media/html5.js file, so I may change it a bit.

@gkatsev
Copy link
Member Author

gkatsev commented May 8, 2013

Updated with a fix to vjs.ANDROID_VERSION and the canPlayType using vjs.IS_OLD_ANDROID.
It might be a bit weird to apply because media.html5.js is still in a file and it isn't media/html5.js

@heff heff closed this in 00a043f Jun 26, 2013
@gkatsev gkatsev deleted the fix/userAgentDetection branch August 12, 2015 18:49
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.

2 participants