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

Fix Uncaught TypeError #7820

Merged
merged 2 commits into from
Sep 11, 2024
Merged

Fix Uncaught TypeError #7820

merged 2 commits into from
Sep 11, 2024

Conversation

liviuconcioiu
Copy link
Collaborator

@liviuconcioiu liviuconcioiu commented Sep 11, 2024

@sanchezzzhak, @sgiehl can you double check this? I've got this error when testing the code in Chrome after page refresh:

PHP Fatal error:  Uncaught TypeError: DeviceDetector\Parser\Device\AbstractDeviceParser::getDeviceName(): Argument #1 ($deviceType) must be of type int, string given, called in Z:\GitHub\device-detector\Parser\Device\AbstractDeviceParser.php on line 2271 and defined in Z:\GitHub\device-detector\Parser\Device\AbstractDeviceParser.php:2075
<?php

header('Accept-CH: Sec-CH-UA, Sec-CH-UA-Mobile, Sec-CH-UA-Platform, Sec-CH-UA-Platform-Version, Sec-CH-UA-Full-Version, Sec-CH-UA-Full-Version-List, Sec-CH-UA-Arch, Sec-CH-UA-Model, Sec-CH-UA-Form-Factors, Sec-CH-UA-Bitness, Sec-CH-UA-WoW64');

include_once 'path/to/spyc/Spyc.php';
include_once 'path/to/device-detector/autoload.php';

use DeviceDetector\ClientHints;
use DeviceDetector\DeviceDetector;
use DeviceDetector\Parser\Device\AbstractDeviceParser;

AbstractDeviceParser::setVersionTruncation(AbstractDeviceParser::VERSION_TRUNCATION_NONE);

$result = DeviceDetector::getInfoFromUserAgent($_SERVER['HTTP_USER_AGENT'], ClientHints::factory($_SERVER));

echo Spyc::YAMLDump($result, 2, 0);

Feel free to push commits if the fix is not okay.

Also, probably the Usage in README should be updated, to let the user know he should request all the headers from browser for detection to fully work. There's an open issue where the model is not detected, and I have the impression this is the cause. By default in Chrome I only get this:

[HTTP_SEC_CH_UA_PLATFORM] => "Windows"
[HTTP_SEC_CH_UA_MOBILE] => ?0
[HTTP_SEC_CH_UA] => "Chromium";v="130", "Google Chrome";v="130", "Not?A_Brand";v="99"

@sanchezzzhak sanchezzzhak merged commit 4754955 into matomo-org:master Sep 11, 2024
15 checks passed
@liviuconcioiu liviuconcioiu deleted the fix branch September 11, 2024 10:27
Comment on lines +2267 to +2268
foreach (self::$clientHintFormFactorsMapping as $formFactor => $deviceType) {
$hasDeviceType = $formFactors[$formFactor] ?? null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that code still inaccurate? If no formfactor matches, the device type will now be always set to the last one in self::$clientHintFormFactorsMapping. is that intended?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants