Browser support: Check iOS Safari engine for all iOS browsers#10002
Browser support: Check iOS Safari engine for all iOS browsers#10002
Conversation
changelog: Internal, Browser Support, Improve browser detection for iOS browsers
app/services/browser_support.rb
Outdated
| def matchers(mapping) | ||
| @matchers ||= browser_support_config.flat_map do |config_entry| | ||
| key, version = config_entry.split(' ', 2) | ||
| browser_matcher = BROWSERSLIST_TO_BROWSER_MAP[key] | ||
| browser_matcher = mapping[key.to_sym] |
There was a problem hiding this comment.
if the passed in mapping is now variable, that will mess with the memoization here? if we memoize based on the result of a cached iOS or Android one, then that will affect future calls?
There was a problem hiding this comment.
Ooh, yeah, good call. At least at a glance I feel like that would be an issue.
There was a problem hiding this comment.
maybe we memoize the full set of mappings from the constant still and do matchers.slice()?
There was a problem hiding this comment.
Not sure it's exactly what you had in mind, but I think 7511389 should address this. The main challenge is that the matchers shape as an array made it difficult to "pick" specific browser matchers, so I restructured it as a hash.
app/services/browser_support.rb
Outdated
| end | ||
| version_test = low_version && ">= #{low_version}" | ||
| matcher = proc { |browser| browser_matcher.call(browser, version_test) } | ||
| [[key, matcher]] |
There was a problem hiding this comment.
the double array seems weird to me? are we trying to avoid a second iteration if we did next nil + .compact.to_h?
There was a problem hiding this comment.
the double array seems weird to me? are we trying to avoid a second iteration if we did
next nil+.compact.to_h?
Subconsciously I might have been trying to avoid that, though it's not the most performance-critical code since the whole thing is memoized anyways. I also don't know if I find it especially more or less clear one way or the other.
Another option is a reduce-y like operation? (Probably the most efficient, too)
diff --git a/app/services/browser_support.rb b/app/services/browser_support.rb
index 65983341e2..6ce3030d58 100644
--- a/app/services/browser_support.rb
+++ b/app/services/browser_support.rb
@@ -50,3 +50,3 @@ class BrowserSupport
def matchers
- @matchers ||= browser_support_config.flat_map do |config_entry|
+ @matchers ||= browser_support_config.each_with_object({}) do |config_entry, result|
key, version = config_entry.split(' ', 2)
@@ -54,3 +54,3 @@ class BrowserSupport
browser_matcher = BROWSERSLIST_TO_BROWSER_MAP[key]
- next [] if !browser_matcher
+ next if !browser_matcher
@@ -60,4 +60,5 @@ class BrowserSupport
matcher = proc { |browser| browser_matcher.call(browser, version_test) }
- [[key, matcher]]
- end.to_h
+ result[key] = matcher
+ end
end
🛠 Summary of changes
Adjusts browser support detection to consider all iOS browsers as checking their conformance against the iOS platform version, rather than for the specific browser. Since all browsers on iOS run on Safari (at least for the time being), this should produce a more accurate result for browser support.
This refactors the internal logic to force specific platforms to check a subset of the browser mappings rather than the full set, since in the case of Android WebView and iOS browsers, we only want to check Android or iOS Safari supports explicitly. This avoids having to add additional checks to exclude these platforms in other matchers.
Related Slack discussion: https://gsa-tts.slack.com/archives/C0NGESUN5/p1706209103652959?thread_ts=1706206479.733399&cid=C0NGESUN5
📜 Testing Plan
Verify specs pass:
Bonus points: Check that error logging script markup is only added to the page based on if eligible iOS browser satisfies the iOS Safari constraint, e.g. overriding the user agent string.