Skip to content

Commit

Permalink
Improves detection for Chromium based browsers (matomo-org#7798)
Browse files Browse the repository at this point in the history
* Improves detection for Chromium based browsers
* Fix test for TV-Browser Internet

---------

Co-authored-by: Tutik Alexsandr <sanchezzzhak@ya.ru>
  • Loading branch information
liviuconcioiu and sanchezzzhak authored Sep 19, 2024
1 parent b48722c commit 481198a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
11 changes: 9 additions & 2 deletions Parser/Client/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1002,9 +1002,9 @@ public function parse(): ?array
}

// If client hints report Chromium, but user agent detects a Chromium based browser, we favor this instead
if ('Chromium' === $name
if (('Chromium' === $name || 'Chrome Webview' === $name)
&& !empty($browserFromUserAgent['name'])
&& 'Chromium' !== $browserFromUserAgent['name']
&& !\in_array($browserFromUserAgent['short_name'], ['CR', 'CV', 'AN'])
) {
$name = $browserFromUserAgent['name'];
$short = $browserFromUserAgent['short_name'];
Expand Down Expand Up @@ -1089,6 +1089,13 @@ public function parse(): ?array
$engineVersion = '';
}

// This browser simulates user-agent of Firefox
if ('TV-Browser Internet' === $name && 'Gecko' === $engine) {
$family = 'Chrome';
$engine = 'Blink';
$engineVersion = '';
}

return [
'type' => 'browser',
'name' => $name,
Expand Down
13 changes: 12 additions & 1 deletion Tests/Parser/Client/fixtures/browser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9914,6 +9914,17 @@
engine: Blink
engine_version: 106.0.5249.199
family: Chrome
-
user_agent: Mozilla/5.0 (Linux; U; Android 11; moto g(9) play Build/RPXS31.Q2-58-17-7-3; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/127.0.6533.64 Mobile Safari/537.36 OPR/83.1.2254.73239
client:
type: browser
name: Opera Mobile
version: 83.1.2254.73239
engine: Blink
engine_version: 127.0.6533.64
family: Opera
headers:
Sec-CH-UA: '"Not)A;Brand";v="99", "Android WebView";v="127", "Chromium";v="127"'
-
user_agent: Mozilla/5.0 (Linux; Android 13; motorola edge 5G UW (2021) Build/T1RM33.1-110-17; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/126.0.6478.71 Mobile Safari/537.36 TUSK/0.2.01
client:
Expand Down Expand Up @@ -10063,7 +10074,7 @@
type: browser
name: TV-Browser Internet
version: ""
engine: ""
engine: Blink
engine_version: ""
family: Chrome
headers:
Expand Down
4 changes: 2 additions & 2 deletions Tests/fixtures/clienthints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1217,15 +1217,15 @@
client:
type: browser
name: Aloha Browser
version: ""
version: 5.10.4
engine: Blink
engine_version: 123.0.0.0
device:
type: smartphone
brand: Fairphone
model: FP5
os_family: Android
browser_family: Chrome
browser_family: Unknown
-
user_agent: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Mobile Safari/537.36
headers:
Expand Down

0 comments on commit 481198a

Please sign in to comment.