Skip to content

Commit

Permalink
Improves detection for frozen client hints in Linux (#7831)
Browse files Browse the repository at this point in the history
  • Loading branch information
liviuconcioiu authored Sep 18, 2024
1 parent c5dec4f commit 98f90cc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Parser/Device/AbstractDeviceParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2162,6 +2162,15 @@ public function parse(): ?array
));
}

// is freeze user-agent then restoring the original UA for the device definition
if ('' !== $deviceModel && $this->hasDesktopFragment()) {
$this->setUserAgent((string) \preg_replace(
'(X11; Linux x86_64)',
\sprintf('X11; Linux x86_64; %s', $deviceModel),
$this->userAgent
));
}

if ('' === $deviceModel && $this->hasUserAgentClientHintsFragment()) {
return $this->getResult();
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/DeviceDetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ public function testNotSkipDetectDeviceForClientHints(): void
{
$dd = $this->createPartialMock(Mobile::class, ['hasDesktopFragment']);

$dd->expects($this->once())->method('hasDesktopFragment')->willReturn(true);
$dd->expects($this->exactly(2))->method('hasDesktopFragment')->willReturn(true);

// simulate work not use clienthints
$dd->setUserAgent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Safari/537.36');
Expand Down
25 changes: 25 additions & 0 deletions Tests/fixtures/clienthints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1200,3 +1200,28 @@
model: Explr 9
os_family: Android
browser_family: Chrome
-
user_agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.134 Safari/537.36 OPR/88.0.4412.53
headers:
Sec-CH-UA: '" Not A;Brand";v="99.0.0.0", "Chromium";v="102.0.5005.134"'
Sec-CH-UA-Platform: "Android"
Sec-CH-UA-Mobile: "?0"
Sec-CH-UA-Full-Version: "102.0.5005.134"
Sec-CH-UA-Platform-Version: "9.0.0"
Sec-CH-UA-Model: "RVL-AL09"
os:
name: Android
version: 9.0.0
platform: x64
client:
type: browser
name: Opera
version: 88.0.4412.53
engine: Blink
engine_version: 102.0.5005.134
device:
type: smartphone
brand: Huawei
model: Honor Note 10
os_family: Android
browser_family: Opera

0 comments on commit 98f90cc

Please sign in to comment.