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

How to hack the iOS >=9.2 WebKit limitation that blocks deviceorientation and devicemotion events access from cross-origin iframes? #3422

Closed
gino8080 opened this issue Mar 8, 2018 · 3 comments

Comments

@gino8080
Copy link

gino8080 commented Mar 8, 2018

With iOS 9.2 WebKit now blocks deviceorientation and devicemotion event access from cross-origin iframes. bug link

  • A-Frame Version: latest
  • Platform / Device: Ios webkit >= 9.2

as a dirty solution I was thinking about using the iframe postMessage to send devicemotions to the child iframe
something like this:

Father page

if (window.DeviceMotionEvent) {

        /* Add a listener for the devicemotion event */
        window.ondevicemotion = function (deviceMotionEvent) {

            /* Get acceleration on x, y and z axis */
            var x = deviceMotionEvent.accelerationIncludingGravity.x;
            var y = deviceMotionEvent.accelerationIncludingGravity.y;
            var z = deviceMotionEvent.accelerationIncludingGravity.z;
            
             var coordinates = deviceMotionEvent.accelerationIncludingGravity;
            console.log(coordinates)
            /* Get the interval (ms) at which data is obtained from the underlying hardware */
            
            //send the accleration coordinates from parent to child iframe 
            //"*" used to avoid cors protection
            jQuery("#myChildIframe")[0].contentWindow.postMessage(coordinates, '*');
}

Children iframe

window.onload = function () {
    window
        .addEventListener('message', function (e) {
           //e.data are the accelerometer from father
           //now how to pass the devicemotions coordinates to aframe??
           
        })
}

but how to send the father devicemotion coordinates to the child iframe aframe?

@calrk
Copy link
Contributor

calrk commented Mar 8, 2018

You could try something like the following and see if it works for you.

...

.addEventListener('message', function (e) {
    var event = document.createEvent('Event');
    event.initEvent('ondevicemotion', true, true);

    event.accelerationIncludingGravity = e.data;

    window.dispatchEvent(event);
});

...

@dmarcos
Copy link
Member

dmarcos commented Mar 17, 2018

Thanks foe filing. I suggest reopening this question on StackOverflow. We use issues for bugs and feature requests.

@dmarcos dmarcos closed this as completed Mar 17, 2018
@jdreetz
Copy link

jdreetz commented Dec 12, 2018

There's an example of how to resolve this in the cardboard-vr-display repo. Turns out FusionPoseSensor already listens for fake devicemotion events using postmessage, you just have to send them with the right formatting - https://github.com/immersive-web/cardboard-vr-display/blob/master/examples/iframe.html

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

4 participants