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

device has properties with undefined value #182

Closed
aifrim opened this issue Jun 7, 2016 · 7 comments
Closed

device has properties with undefined value #182

aifrim opened this issue Jun 7, 2016 · 7 comments

Comments

@aifrim
Copy link

aifrim commented Jun 7, 2016

Windows 7 Enterprise:
Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36

Windows 10 Enterprise:
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36

I suggest adding the model as being pc

@sheinbergon
Copy link

@aifrim it's an interesting subject for discussion.

Desktops/Laptops Browsers don't have an indication telling that they are actually running on such devices ( as opposed to tablets/smartphones that have the model incorporated into the UA String ). You can transitively deduce it's a "pc" by ruling out other options/applying other heuristics ( say, windows 7 only runs on pc, so it must be a pc )

But I don't think that logic is something you should implement on the framework level, because the permutations are endless. I personally think ua-parser-js should stick to identifications it can make directly as opposed to indirect,transitive ones

@faisalman WDYT ?

@faisalman
Copy link
Owner

Completely agree with @sheinbergon in this regard. I decide to not adding this for the moment, maybe sometime in the near future.. Thanks for your suggestion 👍

@alexsloan
Copy link

I totally get the explanation, would be great if the docs indicated this though.

@Mochnant
Copy link

Speaking as a developer trying to solve a problem, while I understand this reasoning, it seems like a hole in the library's functionality. The many requests closed over the years seem to hint that others have the same issue.

Respectfully, is it possible to revisit this decision?

@shenders13
Copy link

shenders13 commented Jul 3, 2023

Hi all 👋

I have a web app with two breakpoints:

  • Mobile: Less than 768px
  • Desktop: Greater than 768px

On the server, I need to use the user-agent to determine which regime I'm in.

Does the following logic seem like a reasonable approach to you?

switch (device.type) {
  case 'wearable':
  case 'mobile':
    // Device width probably less than 768px. Show mobile version of app.
    return 'mobile';
  case 'console':
  case 'tablet':
  case 'smarttv':
  case 'embedded':
  case undefined:
  default:
    // Device width probably greater than 768px. Show desktop version of app.
    return 'desktop';
}

It's obviously not perfect e.g. if someone is on a tall phone (> 768px) and they're in horizontal mode, then we'll still show the "mobile" UI even though the screen width is > 768px. But it seems like this will work in ~95% of use cases?

@xinha-sh
Copy link

    // Device width probably greater than 768px. Show desktop version of app.

Did this work. Stuck on same thing

@fineshop
Copy link

fineshop commented Sep 6, 2023

Hi all 👋

I have a web app with two breakpoints:

  • Mobile: Less than 768px
  • Desktop: Greater than 768px

On the server, I need to use the user-agent to determine which regime I'm in.

Does the following logic seem like a reasonable approach to you?

switch (device.type) {
  case 'wearable':
  case 'mobile':
    // Device width probably less than 768px. Show mobile version of app.
    return 'mobile';
  case 'console':
  case 'tablet':
  case 'smarttv':
  case 'embedded':
  case undefined:
  default:
    // Device width probably greater than 768px. Show desktop version of app.
    return 'desktop';
}

It's obviously not perfect e.g. if someone is on a tall phone (> 768px) and they're in horizontal mode, then we'll still show the "mobile" UI even though the screen width is > 768px. But it seems like this will work in ~95% of use cases?

You can also use:

const isDesktop = device.type === undefined || !['wearable', 'mobile'].includes(device.type);

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

8 participants