-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Flag to disable devtools #191
Comments
It would probably work to put this at the top of your page (before react is loaded). That would effectively prevent the devtools from accessing React's context. <script>
window.__REACT_DEVTOOLS_GLOBAL_HOOK__.inject = function () {}
</script> Keep in mind, though, that anybody can see & mess w/ network requests in chrome :) so if you're trying to prevent cheating, make sure you have checks server-side as well |
Thanks, this is exactly what I need! |
@jaredly I'm wondering if this is still the recommended option if we want to disable react devtools for a given environment? |
yup, it should work |
How are you guys handling mobile browsers which throw:
|
try checking for
|
Okay, found a way to keep even that function from getting injected/involved. I just changed the disabler code to this:
|
@Venryx Thanks, your code worked for me! |
@Venryx Thank you very much! This just works :) For anyone who, like me, uses TypeScript, here is a TS version of the code above (extracted in a function): const disableReactDevTools = (): void => {
const noop = (): void => undefined;
const DEV_TOOLS = (window as any).__REACT_DEVTOOLS_GLOBAL_HOOK__;
if (typeof DEV_TOOLS === 'object') {
for (const [key, value] of Object.entries(DEV_TOOLS)) {
DEV_TOOLS[key] = typeof value === 'function' ? noop : null;
}
}
}; And then just call the |
If you want to disable in if (!window.location.port && typeof window.__REACT_DEVTOOLS_GLOBAL_HOOK__ === 'object') {
window.__REACT_DEVTOOLS_GLOBAL_HOOK__.inject = function () {}
} |
Hi there! I just want to let you know, and for future visitors, that I published a package that implements this feature so that I can resure it on all my React projects. |
@sagar-gavhane where exactly do you put this piece of code? |
@max77p It should be placed at the start of the first-run script, I believe. (that's where I place my variant anyway) |
@max77p If you want to disable the react devtools, there's an explanation on how to use the package I published here: https://github.com/fvilers/disable-react-devtools#readme |
@Venryx do you add anything else to lock down the tools or just this piece of line? |
@max77p No, I use just the (5/6) lines shown in my comment. |
@skirankumar7 You can't. If the property of the state is a boolean, it will show as checkbox in the devtools. Your only options are to remove the devtools completely with the code people posted on this issue or live with it |
Thanks @pietrofxq |
Hey guys, the new devtools is really awesome! I was just wondering if there's a flag I can set in a react app to prevent non-developers from viewing or editing the app with the devtools.
The text was updated successfully, but these errors were encountered: