1

People have already talked about this issue on How can I find the mobile phone manufacturer using javascript on mobile browser and Detecting device brand

What I need is a javascript library with a much more "muscular" device code library than the current version of platform.js

For instance I have this SONY phone and when I run window.navigator.userAgent; it returns the device name as F3311 (sadly platform.js doesn't recognize that). And that means another model from SONY would appear with another device code. There is also HUAWEI and XIAOMI and many other brands.

Is there a javascript library out there with which I can use a sample piece of code like this:

if(userDevice == SONY)
{
//do stuff that is supported by Sony phones only, etc
}
else if (userDevice == HUAWEI)
{
//show stuff that will appear only on Huawei phones, etc
}

These might be useful, http://gs.statcounter.com/vendor-market-share/mobile and https://www.idc.com/promo/smartphone-market-share/vendor

EDIT 1: I have found this https://deviceatlas.com/products/web but I don't know if they are offering just what I need. I will inquire.

HolyResistance
  • 594
  • 1
  • 8
  • 26
  • There are lots of Web browsers for Android, both pre-installed and user-installed. There are no requirements for any of them to include that sort of data in the HTTP headers. I would be disappointed if they did, on privacy/security grounds. More generally, though, asking for libraries or other off-site resources is considered to be off-topic for Stack Overflow. – CommonsWare Jul 01 '19 at 23:49
  • 1
    I respect the strictness of Stack Overflow that is required to maintain a certain level of quality. Nevertheless, I believe there is common good in mentioning things that can be useful for some coders as the more specific we get within the community the more accurate our path will be. – HolyResistance Jul 02 '19 at 00:01

1 Answers1

0

I've found a good list of the device models that I was looking for. To see it just go to https://deviceatlas.com/device-data/devices and click "browse by manufacturer" to reveal it. Now I can try and modify platform.js using that list or write something similar that will be able to detect the brands that I want. (Sure, it would be sweeter if somebody already did that for the top 10 or 20 manufacturers and shared his good code.)

EDIT 1: There is also mobile-detect.js which has a wider manufacturer detection range than platform.js as you may see it in their code on https://github.com/hgoebl/mobile-detect.js/blob/master/mobile-detect.js but still some major brands are either poorly covered or totally missing in that one too. Including every single manufacturer seems to be beyond the limits of monolancers anyway. It's like trying to chart the world-map on your own by traveling on foot. So it is not surprising that such an extensive service would have to be a paid service.

EDIT 2: Wait! I didn't know this existed: https://github.com/faisalman/ua-parser-js It is indeed muscular ! It looks like it is able to recognize my Sony phone. GOOD! (At least with mobile Chrome, it does. I tried mobile Firefox too but it doesn't work.) As for Huawei unfortunately it didn't recognize it. Still it may offer some use and to test it you can download it (preferably minified) and use some code like this

<script src="ua-parser.min.js" charset="utf-8"></script>
<script type="text/javascript">

var parser = new UAParser();
var result = parser.getResult();
alert(result.device.vendor);

//this worked for me
var userDevice = result.device.vendor;
if(userDevice == "Sony")
{
// code to be run on Sony devices
}
</script>
HolyResistance
  • 594
  • 1
  • 8
  • 26