Device orientation in mobile Opera is not working

Viewed 69

I have issues making deviceorientation working in Opera browser.

This code works well on my Android/Chrome:

  window.addEventListener('deviceorientation', function(e) {
    console.log(e.webkitCompassHeading || e.compassHeading || e.alpha || 0);
  });

However Opera says 0 all the time. I also tried AbsoluteOrientationSensor and check it with Permission API:

alert("AbsoluteOrientationSensor" in window); // Opera says true

Promise.all([navigator.permissions.query({ name: "accelerometer" }),
             navigator.permissions.query({ name: "magnetometer" }),
             navigator.permissions.query({ name: "gyroscope" })])
   .then(results => {
      if (results.every(result => result.state === "granted")) {
        alert("Permissions granted");
      } else {
        alert("Permissions blocked");
      }
    });

// Opera says Permissions granted

but again: sensor reading (from the basic example in the link below) works in Chrome and is silent in Opera. MDN says Deviceorientation and AbsoluteOrientationSensor should work in Opera, so what am I missing?

0 Answers
Related