Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React native - Programmatically check if in remote JS debugging is enabled

Tags:

On React-Native, how can I know if "Debug JS Remotely" is enabled?

I tried looking in RN docs and various NPM packages, but couldn't find out how...

like image 617
Kuf Avatar asked Aug 18 '16 15:08

Kuf


People also ask

How do I check debug mode in React Native?

You can also use the ⌘D keyboard shortcut when your app is running in the iOS Simulator, or ⌘M when running in an Android emulator on Mac OS and Ctrl+M on Windows and Linux. Alternatively for Android, you can run the command adb shell input keyevent 82 to open the dev menu (82 being the Menu key code).

How enable debugging JS remote in React Native?

Open the developer menu in Chrome and select “Debug JS Remotely” to debug JavaScript code. This will open http://localhost:8081/debugger-ui in a new tab.

How disable remote JS debugging in React Native?

If you are using on MS : ctrl + m , MAC OS : cmd + m , iPhone/android: shake your device then look for the "disable Remote Debug JS" and click it. Show activity on this post. Go to your android settings and clear app data and cache and reload the app remote debugging will be turned off.

How do I enable debugging in react?

When debugging a React app, I often find breakpoints to be very helpful. There are two main ways in which we can use them: By writing the debugger statement in our source code. By clicking on a specific line of the code in the Chrome web browser (or Firefox, Edge, etc.)


2 Answers

How to programmatically check if remote debugging is enabled (just found this peculiar behaviour today on another SO question). Tested on RN 0.43 and with Chrome debugger + React Native Debugger :

const isDebuggingEnabled = (typeof atob !== 'undefined'); 

Edit: just noticed this was asked over half a year ago :D... well, I leave it here for future generations.

like image 72
Samuli Hakoniemi Avatar answered Sep 29 '22 17:09

Samuli Hakoniemi


A class DedicatedWorkerGlobalScope exists iff remote debugging is enabled (it is the constructor of global object in that case). Thus we can:

const haveRemoteDev = (typeof DedicatedWorkerGlobalScope) !== 'undefined'; 
like image 44
Jokester Avatar answered Sep 29 '22 17:09

Jokester