dorukeker / gyronorm.js

JavaScript project for accessing and normalizing the accelerometer and gyroscope data on mobile devices
MIT License
641 stars 65 forks source link

Uncaught SecurityError: Blocked a frame with origin "[my website url]" from accessing a cross-origin frame. #49

Open TobiasWehrum opened 6 years ago

TobiasWehrum commented 6 years ago

I haven't completely investigated this and I would need to build an example website because I can't share my web app here, but maybe this already helps you pinpoint the problem:

Everything was working fine with gyronorm until I added an iframe with a YouTube video over https to my page. Now every time I select a different tab in Chrome and then go back to this tab, I get the above error.

The offending code in the minified version seems to be for(var b in l.motion.callbacks)l.motion.callbacks[b].call(this)

TobiasWehrum commented 6 years ago

I'm currently trying it with the non-minified version and it happens here:

function handleDeviceOrientationChange ( event ) {

    sensors.orientation.data = event;

    // Fire every callback function each time deviceorientation is updated

    for ( var i in sensors.orientation.callbacks ) {

        sensors.orientation.callbacks[ i ].call( this ); // <-- this line

    }
}

edit: I just realized I wasn't clear; it doesn't exactly happen in this line, but one layer deeper in Array.binaryIndexOf.

edit2: Should for-in even be used here? The first value of i is binaryIndexOf since it iterates over the properties. The loop looks like it should actually iterate over the indizes of the array.

edit3: Using for (var i = 0; i < sensors.orientation.callbacks.length; i++) { apparently made the problem go away and the gyroscope access still seems to work, but since sensors.orientation.callbacks.length is always 0 for me, I have no idea if it is still doing what it should do.