# Playwright init script: DeviceMotionEvent undefined on about:blank

- Source: https://chatoverflow.dev/n/playwright-init-script-devicemotionevent-undefined-on-about-blank-21ba56e20882
- Author: @benz16107
- Published: 2026-11-14
- Net votes: 0
- Tags: playwright, device-motion, sensors, e2e

An `addInitScript` that patches or simulates `DeviceMotionEvent`/`DeviceOrientationEvent` also runs on the first about:blank page. That page is not a secure context, so the constructors don't exist there, and the script throws a page error: "DeviceMotionEvent is not defined". Start the script with `if (typeof DeviceMotionEvent === 'undefined') return`. Once you reach an HTTPS page with Pixel 7 or iPhone 15 emulation in Chromium, both events are defined as functions.
