Why Tilt Games Break on Game Portals: Cross-Origin Iframes and Permissions Policy
Tilt controls can stop working when a game is embedded in someone else's page. One structural reason: web game portals embed games inside cross-origin <iframe> elements, and browser Permissions Policy only allows gyroscope and accelerometer access in a cross-origin frame if the parent page explicitly delegates it.
In this article
1. The Default Allowlist Is self
Under the W3C Permissions Policy specification and MDN's Permissions-Policy documentation, the gyroscope, accelerometer, and magnetometer directives all share a default allowlist of self.
A default allowlist of self means two things:
- First-party documents work automatically: A top-level page (or same-origin iframe) served over HTTPS is allowed to request and receive motion sensor events.
- Cross-origin frames are blocked by default: Any embedded frame loaded from a CDN, subdomain, or third-party game hosting origin cannot read the sensors unless the parent document grants permission explicitly.
2. Which Directives Govern deviceorientation and devicemotion
Many developers think of Permissions Policy only in terms of the newer Generic Sensor API constructors (new Gyroscope(), which throws a SecurityError when blocked). However, the W3C Device Orientation and Motion specification ties legacy window events directly to those same policy-controlled features:
| Browser Event | Required Policy-Controlled Features | Default Allowlist |
|---|---|---|
devicemotion |
accelerometer and gyroscope |
self |
deviceorientation (relative) |
accelerometer and gyroscope |
self |
deviceorientationabsolute |
accelerometer, gyroscope, and magnetometer |
self |
3. Why Cross-Origin Iframes Fail Silently
When you attach window.addEventListener('deviceorientation', handler) inside a cross-origin iframe that lacks sensor delegation, JavaScript does not throw an error. The listener registers, but per the W3C spec the browser does not fire the events when the document is not allowed to use the required sensors. A game that only listens for tilt appears frozen.
For a cross-origin iframe to receive motion and orientation data, two conditions must both hold:
- The embedding page's HTTP
Permissions-Policyheader, if it sets one, must not block the directives for the frame (for instance withgyroscope=()). - The embedding HTML
<iframe>tag must explicitly delegate the sensors using theallowattribute:
<iframe
src="https://games.example.com/tilt-maze.html"
allow="accelerometer; gyroscope">
</iframe>Web game portals commonly serve games from a different origin than the page that embeds them. If the embedding page does not delegate accelerometer and gyroscope in the allow attribute, tilt controls cannot work in that frame. We have not audited any specific portal, so check the embed code of the one you care about.
4. The iOS requestPermission() and HTTPS Gates
Even on first-party domains, mobile browsers enforce two additional rules documented on MDN's DeviceOrientationEvent.requestPermission() reference:
- Secure context (HTTPS): Orientation and motion APIs are exposed only over HTTPS. Plain HTTP pages fail.
- Transient user activation: On iOS Safari,
DeviceOrientationEvent.requestPermission()must run inside a direct user gesture such as a buttonclickhandler. Called without a user gesture while the permission is still undecided, it rejects with aNotAllowedError. Chrome and Firefox do not have this method, so the prompt is an iOS Safari step.
5. How First-Party Hosting (and Desktop Fallbacks) Solve It
On Privacy Pix Tools, our tilt games (Tilt Maze, Slope Rush, and Wobble) and sensor utilities (Gyroscope Test and Bubble Level) run directly on our own HTTPS origin rather than inside third-party frames. That means the default self allowlist permits sensor access immediately once the player taps Play.
Just as important, our shared tilt engine runs a short watchdog timer after Play is tapped. If no sensor event arrives within a second, whether because the visitor is on a desktop computer without a gyroscope, denied iOS permission, or opened the page in a restricted webview, the game smoothly switches to mouse, touch drag, and keyboard controls so it is never stuck.
Test your own browser's sensor path
See live beta, gamma, alpha, sample rate, and whether orientation or motion is blocked.
Run Online Gyroscope TestFrequently Asked Questions
Why do DeviceOrientation events stop firing inside an iframe?
Under W3C Permissions Policy, the gyroscope, accelerometer, and magnetometer features have a default allowlist of self. When a game runs inside a cross-origin iframe, the browser does not fire sensor events unless the parent page delegates those features in the iframe allow attribute and does not block them in its HTTP Permissions-Policy header.
Which Permissions Policy directives control motion and orientation events?
The W3C Device Orientation and Motion specification binds devicemotion and relative deviceorientation events to both accelerometer and gyroscope, and deviceorientationabsolute to accelerometer, gyroscope, and magnetometer.
Why does DeviceOrientationEvent.requestPermission() fail on some pages?
DeviceOrientationEvent.requestPermission() needs a secure HTTPS context and transient user activation, such as a click or tap. Without a user gesture it rejects with NotAllowedError. Separately, a frame that lacks Permissions Policy delegation never receives sensor events, even if the user says yes.
How can developers test whether a frame or browser is blocking sensors?
Add a short watchdog timer after attaching the deviceorientation listener, or open a first-party diagnostic page such as our Online Gyroscope Test directly over HTTPS to isolate hardware, permission, and iframe blocks.
Verified Specifications and References
- W3C Device Orientation and Motion Specification - policy-controlled features and event dispatch rules.
- W3C Permissions Policy Specification - iframe delegation and allowlists.
- MDN: Permissions-Policy gyroscope directive - default allowlist
selfand syntax. - MDN: Permissions-Policy accelerometer directive - default allowlist
selfand syntax. - MDN: DeviceOrientationEvent.requestPermission() - secure context and transient user activation.