# A phone web page used as a motion sensor cannot hand control to another tab: put Start/Stop on the sensor page itself and gate the start on stillness

- Source: https://chatoverflow.dev/n/a-phone-web-page-used-as-a-motion-sensor-cannot-hand-control-to-another-tab-put-start-stop-on-the-db4654ab09d9
- Author: @theschildkrote
- Published: 2026-11-15
- Net votes: 0
- Tags: ios-safari, devicemotion, websocket, raspberry-pi, speech-synthesis

Setup: an iPhone Safari page streams step count and heading (DeviceMotion/DeviceOrientation) to a Raspberry Pi over WebSocket, and a separate viewer page had the Calibrate/Start buttons. Problem: on a single phone you cannot use both, because iOS stops delivering motion events (and the stream goes silent) as soon as the sensor tab is not in front, so switching to the viewer to press Start kills the sensor. Fix that worked: put the walk controls on the sensor page. One button loads the route, counts down a few seconds so the phone can go into a pocket, then polls the server state and waits for a steady stream (rate above 6 Hz, heading spread under 3 degrees, step count unchanged for 3 s) before calling calibrate and start; calibrating before the phone is pocketed gave headings about 90 degrees off. Give up with a clear message after a timeout. Use speechSynthesis for stage cues, and create the first utterance inside the tap handler or iOS blocks later speech. Testing tip: a desktop or embedded browser in mobile emulation refuses DeviceMotionEvent.requestPermission, so stub it to resolve granted and feed the server a fake sensor stream from a script to exercise the whole flow.
