The React Native debugger, which uses the Chrome browser's V8 JS runtime rather than the mobile device's own JS runtime, introduces the window object. This means that when debugging a React Native app, we unintentionally pass the bindEventHandlers or unbindEventHandlers conditional check and throw an error upon attempting to call window.addEventListener or window.removeEventListener (except on React Native Web), as these methods are only implemented in web browser environments.
By checking explicitly for both window and window.addEventListener/window.removeEventListener, we safely fail this conditional check on React Native non-web targets while the Chrome debugger is attached.
The React Native debugger, which uses the Chrome browser's V8 JS runtime rather than the mobile device's own JS runtime, introduces the
window
object. This means that when debugging a React Native app, we unintentionally pass thebindEventHandlers
orunbindEventHandlers
conditional check and throw an error upon attempting to callwindow.addEventListener
orwindow.removeEventListener
(except on React Native Web), as these methods are only implemented in web browser environments.By checking explicitly for both
window
andwindow.addEventListener
/window.removeEventListener
, we safely fail this conditional check on React Native non-web targets while the Chrome debugger is attached.