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

Safari Desktop Not Working - Fix Included #430

Open
route413 opened this issue Oct 11, 2023 · 0 comments
Open

Safari Desktop Not Working - Fix Included #430

route413 opened this issue Oct 11, 2023 · 0 comments

Comments

@route413
Copy link

route413 commented Oct 11, 2023

Description

View360 does not load on Safari when viewing from the Desktop. The error that appears in the console is - ReferenceError: Can't find variable: DeviceMotionEvent - Reason being is that DeviceMotionEvent does not exist for Safari Desktop.

The fix that works for me is to only target DeviceMotionEvent when on mobile devices. Solution:

In view360-4.0.0-beta7.js (https://cdn.jsdelivr.net/npm/@egjs/view360@4.0.0-beta.7/dist/view360.pkgd.js), change:

   const sensorCanBeEnabledIOS = () => {
      return window.isSecureContext && !!DeviceMotionEvent && "requestPermission" in DeviceMotionEvent;
    };

to

const sensorCanBeEnabledIOS = () => {
        var ua = window.navigator.userAgent,
            iOS = !!ua.match(/iPad/i) || !!ua.match(/iPhone/i),
            webkit = !!ua.match(/WebKit/i),
            iOSSafari = iOS && webkit && !ua.match(/CriOS/i);

      if (iOSSafari && window.isSecureContext && !!DeviceMotionEvent && "requestPermission" in DeviceMotionEvent) {
          return true;
      } else {
          return false;
      }
    };

Steps to check or reproduce

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

1 participant