4

The kind of logging I would want to do would change depending on which environment I'm in. Also, on a practical level, I might want to disable certain animations when debugging in chrome because those are painfully slow when running across the bridge.

To clarify, detection of debugging remotely in chrome is not the same thing as detecting whether the app is in __DEV__ mode or using the packager. Specifically, I'm referring to when you select "Start Remote Debugging" (previously "Start Debugging in Chrome") in the developer menu.

eremzeit
  • 4,055
  • 3
  • 30
  • 32
  • Possible duplicate of [React Native DEV and PROD variables](http://stackoverflow.com/questions/33264431/react-native-dev-and-prod-variables) – FuzzyTree Aug 11 '16 at 18:39

3 Answers3

2

typeof location !== 'undefined'

When debugging remotely, there is no origin or location property on global variable.

It works for me on React Native 44.0.

Shaoxing
  • 21
  • 2
1

Ah, I figured it out myself. There might be better ways but you can use feature detection. The following snippet from the anonymous.js library does the trick.

let isNode = ("undefined" !== typeof global) && ('[object global]' === Object.prototype.toString.call(global))
let isWebWorker = !isNode && ('undefined' !== typeof WorkerGlobalScope) && ("function" === typeof importScripts) && (navigator instanceof WorkerNavigator)

When debugging remotely in chrome your code is run inside a WebWorker.

eremzeit
  • 4,055
  • 3
  • 30
  • 32
0

This short snippet worked for me

typeof importScripts === "function"
vikeri
  • 642
  • 6
  • 16