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

Does not detect iOS 13 beta #95

Closed
stevenalanstark opened this issue Sep 12, 2019 · 8 comments
Closed

Does not detect iOS 13 beta #95

stevenalanstark opened this issue Sep 12, 2019 · 8 comments

Comments

@stevenalanstark
Copy link

We are testing on the iOS 13 beta, and mobile detect is failing. This includes the demo.

Here is the results of the demo:

mobile()=
├─ phone()=
└─ tablet()=
mobileGrade()=A
os()=
userAgent()=
is('WebKit')=true
version('Version')=13.01
version('Opera')=13.01
version('Opera Mobi')=13.01
version('Safari')=13.01
version('Webkit')=605.115
versionStr('iOS')=X
version('BlackBerry')=13.01

This causes the website to be treated as desktop because the functions for mobile, phont and tablet, as well as os and userAgent, all return null.

@stevenalanstark
Copy link
Author

related: bowser-js/bowser#329

@naranjamecanica
Copy link

Latest iPhone GM build has the following user agent Mozilla/5.0 (iPhone; CPU iPhone OS 13_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 and is correctly detected:

getPlatform() = {type: "mobile", vendor: "Apple", model: "iPhone"}
getOS() = {name: "iOS", version: "13.0"}

iPadOS 13 is a different story since Apple just sends a desktop user agent.

@hgoebl
Copy link
Owner

hgoebl commented Sep 13, 2019

Thanks for contributing, but...

  1. This is the wrong project to tell about userAgent and detection. As stated while creating the issue, goto to Mobile-Detect PHP project.
  2. Those guys using the lib in the browser should use other ways than userAgent. See Readme.

@hgoebl hgoebl closed this as completed Sep 13, 2019
@stevenalanstark
Copy link
Author

stevenalanstark commented Sep 13, 2019

The current state of things is:

  1. User agent detection for iPad on 13 beta vs OSX is not possible, the user agent strings are identical.
  2. The only reliable work around ( that I'm aware of ) at this time is to ask if the device supports touch events. This is a very temporary solution that will break when OSX releases a touch screen.

Mobile-Detect PHP is unrelated to this issue.

@hgoebl
Copy link
Owner

hgoebl commented Sep 14, 2019

From the decision of Apple to remove iPad signature from userAgent string, it can be concluded that they don't want iPad to be treated differently than desktop. Ask Apple if it was their intention.

This library only takes the regular expressions from the PHP project (thanks to Serban) and doesn't apply special logic to try to do more detections. Most consumers use the lib server-side with Node.js and don't have info about touch/no-touch.

In Readme, there is a note that the lib should not be used directly everywhere in the code. It should be wrapped. In the wrapper, you can add touch-detection and all you need to correctly classify the devices.

@stevenalanstark
Copy link
Author

Using a wrapper to implement the touch detection hook is not adequate to solve this issue.

The reason being is that we are only able to test if items are defined or not, which leaves us in a situation where we classify every null returned value as iPad, which obviously is not a valid solution.

I forked this repo and made a change to the impl.prepareDetectionCache function. At the end, I add the test for touch event and force the cache values to be mobile iOS tablet with an 'A' grade. This is the best solution I was able to come up with, but if anyone has anything better then I'd be happy to hear about it.

@hgoebl
Copy link
Owner

hgoebl commented Sep 21, 2019

There is already a mechanism to extend the class - see Extending.
This gives you a mean to extend/overwrite the standard behavior.
You may send a link to your fork in case you think your change should go to the public version.

@stevenalanstark
Copy link
Author

yes, that is a better way to do extending on most cases. For my case, I opted to modify the original function.

No, I don't think this belongs in the main repo, it would be best to keep this isolates to UA tests as I expect is your intent.

It would be nice to see a better state of the return values in these broken states, as null doesn't leave a lot of options after the fact.

If anyone is looking to implement their own solution, here is the basics:

  1. test for UA's if nothing was found:

Test against multiple iOS 13 UA's, for example:

    // "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Safari/605.1.15"
    // "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.1 Safari/605.1.15"
  1. test if the device has touch. I used this function found in SO:

          var is_touch_device = function() {
            var prefixes = ' -webkit- -moz- -o- -ms- '.split(' ');
            var mq = function(query) {
              return window.matchMedia(query).matches;
            };

            if (('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) {
              return true;
            }

            // include the 'heartz' as a way to have a non matching MQ to help terminate the join
            // https://git.io/vznFH
            var query = ['(', prefixes.join('touch-enabled),('), 'heartz', ')'].join('');
            return mq(query);
          };

then set values to the cache:


          if ( is_touch_device() ) {
            // iPad OS 13
            cache.mobile = cache.tablet = "iPad";
            cache.os = "iOS";
            cache.grade = "A";
            cache.phone = null;
          } else {
            // OSX
            cache.mobile = cache.tablet = cache.phone = cache.os = null;
            cache.grade = "C";
          }

I expect this issue can be closed here.

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

No branches or pull requests

3 participants