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

Improves detection for client hints fragment #7852

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Parser/Device/AbstractDeviceParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2180,7 +2180,7 @@ public function parse(): ?array
if ('' !== $deviceModel && $this->hasUserAgentClientHintsFragment()) {
$osVersion = $this->clientHints ? $this->clientHints->getOperatingSystemVersion() : '';
$this->setUserAgent((string) \preg_replace(
'(Android 10[.\d]*; K)',
'(Android (?:10[.\d]*; K|1[1-5]))',
\sprintf('Android %s; %s', '' !== $osVersion ? $osVersion : '10', $deviceModel),
$this->userAgent
));
Expand Down Expand Up @@ -2345,7 +2345,7 @@ protected function hasDesktopFragment(): bool
*/
protected function hasUserAgentClientHintsFragment(): bool
{
return (bool) \preg_match('~Android 10[.\d]*; K(?: Build/|[;)])~i', $this->userAgent);
return (bool) \preg_match('~Android (?:10[.\d]*; K(?: Build/|[;)])|1[1-5]\)) AppleWebKit~i', $this->userAgent);
}

/**
Expand Down
79 changes: 79 additions & 0 deletions Tests/fixtures/clienthints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3605,3 +3605,82 @@
model: HK1RBOX-X4
os_family: Android
browser_family: Chrome
-
user_agent: Mozilla/5.0 (Linux; Android 11) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/126.0.0.0 Mobile DuckDuckGo/5 Safari/537.36
headers:
Sec-CH-UA: '"Not/A)Brand";v="8.0.0.0", "Chromium";v="126.0.6478.186", "DuckDuckGo";v="126.0.6478.186"'
Sec-CH-UA-Platform: "Android"
Sec-CH-UA-Mobile: "?1"
Sec-CH-UA-Full-Version: "126.0.6478.186"
Sec-CH-UA-Platform-Version: "11.0.0"
Sec-CH-UA-Model: "Nokia 7.2"
http-x-requested-with: "com.duckduckgo.mobile.android"
os:
name: Android
version: 11.0.0
platform: ""
client:
type: browser
name: DuckDuckGo Privacy Browser
version: ""
engine: Blink
engine_version: 126.0.0.0
device:
type: smartphone
brand: Nokia
model: "7.2"
os_family: Android
browser_family: Chrome
-
user_agent: Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/127.0.0.0 Mobile DuckDuckGo/5 Safari/537.36
headers:
Sec-CH-UA: '"Not)A;Brand";v="99.0.0.0", "DuckDuckGo";v="127.0.6533.64", "Chromium";v="127.0.6533.64"'
Sec-CH-UA-Platform: "Android"
Sec-CH-UA-Mobile: "?1"
Sec-CH-UA-Full-Version: "127.0.6533.64"
Sec-CH-UA-Platform-Version: "13.0.0"
Sec-CH-UA-Model: "SM-G781V"
http-x-requested-with: "com.duckduckgo.mobile.android"
os:
name: Android
version: 13.0.0
platform: ""
client:
type: browser
name: DuckDuckGo Privacy Browser
version: ""
engine: Blink
engine_version: 127.0.0.0
device:
type: smartphone
brand: Samsung
model: Galaxy S20 FE 5G
os_family: Android
browser_family: Chrome
-
user_agent: Mozilla/5.0 (Linux; Android 14) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/128.0.0.0 Mobile DuckDuckGo/5 Safari/537.36
headers:
Sec-CH-UA: '"Chromium";v="128.0.6613.146", "Not;A=Brand";v="24.0.0.0", "DuckDuckGo";v="128.0.6613.146"'
Sec-CH-UA-Platform: "Android"
Sec-CH-UA-Mobile: "?1"
Sec-CH-UA-Full-Version: "128.0.6613.146"
Sec-CH-UA-Platform-Version: "14.0.0"
Sec-CH-UA-Model: "SM-A137F"
Sec-CH-UA-Form-Factors: "Mobile"
http-x-requested-with: "com.duckduckgo.mobile.android"
os:
name: Android
version: 14.0.0
platform: ""
client:
type: browser
name: DuckDuckGo Privacy Browser
version: ""
engine: Blink
engine_version: 128.0.0.0
device:
type: smartphone
brand: Samsung
model: Galaxy A13
os_family: Android
browser_family: Chrome
Loading