-
Notifications
You must be signed in to change notification settings - Fork 461
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
Improves version detection for Opera and Opera Mobile and improves browser version detection for client hints #7065
base: master
Are you sure you want to change the base?
Changes from 12 commits
0651eb1
d2a8f0d
1c8953d
515dd50
43e1794
f3a9655
c7c1f06
8ccd5c3
36d48a2
1674c2c
f80ec90
8fb2ccb
c13d97b
41a08c6
e355c72
c1859af
616b4b3
93bd022
182f63a
8aedfa6
af60cdf
3f61274
327991d
d6e4b19
945cc04
36c6d4d
05a41d4
76cff82
737d26d
89b1dec
f6e0f04
118eed0
deb42fa
4f36512
49d3069
ce6b520
f7ee8d9
24cde30
c662c2f
ecfe03b
85c63fb
29c22c2
ee2ea81
6e76c22
45f23dc
695564d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -442,6 +442,7 @@ class Browser extends AbstractClientParser | |
'VV' => 'vivo Browser', | ||
'VB' => 'Vision Mobile Browser', | ||
'VM' => 'VMware AirWatch', | ||
'WB' => 'Wave Browser', | ||
'WI' => 'Wear Internet Browser', | ||
'WP' => 'Web Explorer', | ||
'WE' => 'WebPositive', | ||
|
@@ -493,7 +494,7 @@ class Browser extends AbstractClientParser | |
'HP', 'IO', 'TP', 'CJ', 'HQ', 'HI', 'NA', 'BW', 'YO', | ||
'DC', 'G8', 'DT', 'AP', 'AK', 'UI', 'SD', 'VN', '4S', | ||
'2S', 'RF', 'LR', 'SQ', 'BV', 'L1', 'F0', 'KS', 'V0', | ||
'C8', 'AZ', 'MM', 'BT', 'N0', 'P0', 'F3', 'VS', | ||
'C8', 'AZ', 'MM', 'BT', 'N0', 'P0', 'F3', 'VS', 'WB', | ||
], | ||
'Firefox' => [ | ||
'AX', 'BI', 'BF', 'BH', 'BN', 'C0', 'CU', 'EI', 'F1', | ||
|
@@ -656,7 +657,7 @@ public function parse(): ?array | |
$engine = ''; | ||
$engineVersion = ''; | ||
|
||
// If client hints report Chromium, but user agent detects a chromium based browser, we favor this instead | ||
// If client hints report Chromium, but user agent detects a Chromium based browser, we favor this instead | ||
if ('Chromium' === $name | ||
&& !empty($browserFromUserAgent['name']) | ||
&& 'Chromium' !== $browserFromUserAgent['name'] | ||
|
@@ -684,14 +685,21 @@ public function parse(): ?array | |
if ($name === $browserFromUserAgent['name']) { | ||
$engine = $browserFromUserAgent['engine'] ?? ''; | ||
$engineVersion = $browserFromUserAgent['engine_version'] ?? ''; | ||
} | ||
|
||
// In case the user agent reports a more detailed version, we try to use this instead | ||
if (!empty($browserFromUserAgent['version']) | ||
&& 0 === \strpos($browserFromUserAgent['version'], $version) | ||
&& \version_compare($version, $browserFromUserAgent['version'], '<') | ||
) { | ||
$version = $browserFromUserAgent['version']; | ||
} | ||
// In case the user agent reports a more detailed version, we try to use this instead | ||
if (!empty($browserFromUserAgent['version']) | ||
&& 0 === \strpos($browserFromUserAgent['version'], $version) | ||
&& \version_compare($version, $browserFromUserAgent['version'], '<') | ||
) { | ||
$version = $browserFromUserAgent['version']; | ||
} | ||
|
||
// If client hints report Opera or Opera Mobile, we use the version from useragent | ||
if (!empty($browserFromUserAgent['version']) | ||
&& ('OP' === $short || 'OM' === $short) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it known that Opera always reports an incorrect version in the client hints? 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the data I have, everything is incorrect, just for those two browser. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm. I'm not sure how we should handle that. If the browsers might freeze the useragent at some point I'm not sure if the version in useragent will be even updated with new releases or if the number can only be fetched through client hints 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I close this PR then? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sanchezzzhak what do you think about that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current changes give an accurate result. |
||
) { | ||
$version = $browserFromUserAgent['version']; | ||
} | ||
} else { | ||
$name = $browserFromUserAgent['name']; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be moved outside of the if condition. Let's assume the client hints report a
Firefox 16
, but the useragent is spoofed by some tool and containsSafari 20.18
. We would then end up usingFirefox 20.18
, which is wrong.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And, how can we detect the full version then? Some times, client hints don't provide
Sec-CH-UA-Full-Version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In most cases the browser reported in client hints and in user agent should match. In that case the version from user agent will be used. If not I'm not sure if we should simply use the version from useragent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it turns out to be interesting here, opera prints all versions in clienthints
04/04/2022
last version Opera Desktop Linux 85
last version Opera Mobile 68.2
if you look at this list, they just printed versions for all OS
the current tests I am satisfied with the result.
But in the future it will be necessary to come up with something else when useragent is gone.
as an option:
if Mobile OS + opera family get clienthint
OperaMobile=68
if Desktop OS + opera family get
Opera=82