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

Improve Safari user agent string check #3989

Closed
mattjuggins opened this issue Jul 14, 2022 · 5 comments
Closed

Improve Safari user agent string check #3989

mattjuggins opened this issue Jul 14, 2022 · 5 comments
Labels
Milestone

Comments

@mattjuggins
Copy link
Contributor

mattjuggins commented Jul 14, 2022

The following code block exists in CatchupController.js (and formally PlaybackController.js). It checks the User Agent (UA) string and limits the minimum calculated playback rate change that will warrant the playback rate changing.

// Detect safari browser (special behavior for low latency streams)
const ua = typeof navigator !== 'undefined' ? navigator.userAgent.toLowerCase() : '';
const isSafari = /safari/.test(ua) && !/chrome/.test(ua);
minPlaybackRateChange = isSafari ? 0.25 : 0.02;

The UA string checking line originates from this commit from October 2018.

Using a chromium build I came across a UA string where 'chrome' was not present but 'chromium' and 'safari' were, meaning the 'safari only' behaviour incorrectly occurred:

mozilla/5.0 (gbm; px aarch64 1.2.14 neo64) applewebkit/537.36 (khtml, like gecko) chromium/89.0.4389.72 safari/537.3

Understandably, UA string checks are not perfect but this could be made slightly more robust, for example: /safari/.test(ua) && !/chrome/.test(ua) && !/chromium/.test(ua).

I'd suggest just making a small change like this unless there are any better suggestions as this 'safari specific' behaviour is still problematic. Any playback rate changes seem to cause stalls (as detailed here and in duplicate issues) so limiting the rate changes is still sensible.

@dsilhavy
Copy link
Collaborator

@mattjuggins Thanks for reporting this. Maybe it would make sense to include a small library such as https://www.npmjs.com/package/detect-browser for this. I am open for discussions here. We should scan for additional browser checks in the code and then decide if it makes sense to add such a library.

In theory, I want to avoid any browser/platform specific logic but facing reality we will probably always need them.

Anyone got experience with libraries that do browser detection?

@mattjuggins
Copy link
Contributor Author

After a bit of digging, it seems there is no reliable way to detect Safari through feature detection due to some changes after Safari v10. This article however does at least confirm 'chromium' needs to be checked for as well as 'chrome.

From what I can see this appears to be the only place in the core dash.js code where the UserAgent string is checked (there are some instances in the samples).

I have used ua-parser-js in the past which has been reliable. However, the library you suggested @dsilhavy appears to have been updated more recently and is considerably smaller. Bowser is one other option.

If this Safari issue did get resolved in the future then there would be a good argument for accurately checking the browser and version to not apply this different minPlaybackRateChange. This might warrant using a library to do this, even if it is only one check.

@dsilhavy
Copy link
Collaborator

@mattjuggins I integrtaed ua-parser-js in #4001 . Before I merge this, can you please check if it solves your issue

@mattjuggins
Copy link
Contributor Author

Hi @dsilhavy. Apologies, I've been away for a few weeks.
I've tested with the problematic UA string I found and it correctly registers it as not being safari.
Looks good to me 👍

@dsilhavy
Copy link
Collaborator

dsilhavy commented Aug 9, 2022

Fixed in #4001

@dsilhavy dsilhavy added this to the 4.5.0 milestone Aug 9, 2022
@dsilhavy dsilhavy closed this as completed Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants