Frequently during development it’s helpful to inspect the behavior of a particular object or function at the console. If you only care about the shape of an object, it’s easy to see in React Native or the web by simply running
Sometimes though you need to not only inspect an object but also interact with it. For example, I often want to test queries on an ImmutableJS object from my app’s state. Typically in web development, when I want to do something like this I’ll put something like
window.myStateObject = myStateObject in the code, and then from the Chrome console try different methods on the exposed
myStateObject. (It goes without saying that this pattern is best saved for exploration at the console – for reusing objects between JS files stick with the ES2015 module syntax.)
However, when I tried this same pattern in React Native recently, to my puzzlement there was no reference to
myStateObject available from the Chrome console. It seemed that nothing I was setting to
self was visible in the debugger.
To fix this, simply change the execution environment in the Chrome console from the default <top frame> to debuggerWorker.js. Once you’ve done so any global variables you’ve defined will be available at the console.