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

iOS Safari version detection #21

Open
chilled-capybara opened this issue Oct 19, 2022 · 0 comments
Open

iOS Safari version detection #21

chilled-capybara opened this issue Oct 19, 2022 · 0 comments

Comments

@chilled-capybara
Copy link

This is potentially a bug, or some imprecision/ambiguity in one of the code comments.

There are two cases related to resolving the iOS version within resolver.rb

# Case A: For Safari, Chrome and others browsers on iOS
# that report as Safari after stripping tags
family = 'iOS' if agent.family.include?('Safari') && agent.os.family == 'iOS'
# Case B: The browser on iOS didn't report as safari,
# so we use the iOS version as a proxy to the browser
# version. This is based on the assumption that the
# underlying Safari Engine used will be *atleast* equal
# to the iOS version it's running on.
if agent.os.family == 'iOS'
return {
family: 'iOS',
version: VersionNormalizer.new(agent.os.version.to_s).call
}
end

Case B explains;

Case B: The browser on iOS didn't report as safari, so we use the iOS version as a proxy to the browser version. This is based on the assumption that the underlying Safari Engine used will be atleast equal to the iOS version it's running on.

However the condition used for this is simply

if agent.os.family == 'iOS'

As such, whether the browser identifies as Safari or not, the version number is set to the os version; making Case A redundant,

The comment would seem to suggest that there should be logic that is specifically checking for the absence of Safari;

if !agent.family.include?('Safari') && agent.os.family == 'iOS'

As background, this stems from the following real-world example;

ua = 'Mozilla/5.0 (iPad; CPU OS 12_5_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.2 Mobile/15E148 Safari/604.1'
matcher = BrowserslistUseragent::Match.new(['ios_saf 12.2-12.5'], ua)
matcher.browser? && matcher.version?(allow_higher: true)

=> true

Where although it is Safari and iOS, it is replacing the browser version 12.1.2 with the os version 12.5.6 and returning a match.
This potentially doesn't match the expectation based on the Case B comment.

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

No branches or pull requests

1 participant