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

getOS throws an error on set-top box #700

Open
gweax opened this issue Jan 9, 2024 · 0 comments
Open

getOS throws an error on set-top box #700

gweax opened this issue Jan 9, 2024 · 0 comments

Comments

@gweax
Copy link

gweax commented Jan 9, 2024

Library version
1.0.37

Describe the bug
When calling getOS() on a Vodafone GigaTV set-top box, an error is thrown TypeError: Cannot read property 'replace' of undefined.

The error happens in the code block starting in https://github.com/faisalman/ua-parser-js/blob/1.0.37/src/ua-parser.js#L868:

if (_isSelfNav && !_os[NAME] && _uach && _uach.platform != 'Unknown') {
  _os[NAME] = _uach.platform  
                   .replace(/chrome os/i, CHROMIUM_OS)
                   .replace(/macos/i, MAC_OS);           // backward compatibility

The browser running on the set-top box is a Opera for Devices 4.22.1, similar to Chrome 94, but with several differences. One difference is that navigator.userAgentData exists, but is an empty object.

So the check _uach succeeds, also does _uach.platform != 'Unknown' (undefined != 'Unknown'). However, _uach.platform.replace() throws the error, since _uach.platform is undefined).

To Reproduce
If you're not a registered developer for that set-top box, there's no way to reproduce the behavior. You can mimic it by setting var _uach = {}; in line 818.

The browser's user agent is Mozilla/5.0, AppleWebKit/537.36, Chrome/92.0.4515.159, Safari/537.36, OPR/46.0.2207.0, OMI/4.22.1, VODAFONE_STB/7.2.A105.99bba.ngc BCM7271/7.2.A105.99bba.ngc/DTIW387/HIGH (Sagemcom_Broadband_SAS, DTIW387_UHD_VF_DE, Wireless)

Expected behavior
getOS() never throws an error.

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

No branches or pull requests

2 participants