AEPKILL / devtools-detector

Detect if DevTools is open
https://blog.aepkill.com/demos/devtools-detector/
MIT License
1.11k stars 104 forks source link

Disable console clearing #46

Closed Valar353 closed 10 months ago

Valar353 commented 2 years ago

Hey! Is it possible to disable console clearing?

RVFET commented 2 years ago

You can overwrite console.clear() method, however it'll be still possible to use Browser's built-in "Clear console" button.

AEPKILL commented 2 years ago

If clear is disabled, a lot of information for detection will appear in the console (every detection loop) If you want the your debugging information not to cleared, you can turn off the detection in the development environment

E.g.:

// __DEV__ may be injected by webpack or other bundle tools
if (!__DEV__) {  devtoolsDetector.launch() }
Valar353 commented 2 years ago

Got it, thanks for the reply. However, the library clears the console before I call the launch method, is there any way to get around this?

AEPKILL commented 2 years ago

I just tried it won't clear the console before call the launch method

jdempcy commented 2 years ago

I am using a package which uses devtoolsDetector (@d-i-t-a/reader) and so I do not have control over devtoolsDetector.launch() nor do I see that anywhere in the reader code. Is there another way to configure devtools-detector not to clear the console?

AEPKILL commented 2 years ago

I am using a package which uses devtoolsDetector (@d-i-t-a/reader) and so I do not have control over devtoolsDetector.launch() nor do I see that anywhere in the reader code. Is there another way to configure devtools-detector not to clear the console?

you can rewrite devtoolsDetector.launch method before import @d-i-t-a/reader

e.g.


devtoolsDetector.launch = () => void

const reader = require("@d-i-t-a/reader")
jdempcy commented 1 year ago

This disables other functionality used by the module for its content protection which requires detecting when the dev tools are open. What I really need to do is disable the console clearing. I actually found a way to do this by just pointing console.clear to an empty function, ilke you did with the launch method. In the index.html for the whole React app I simply add a script like so:

<!-- Disable console.clear() for debugging purposes -->
<script type="text/javascript">console.clear = () => {};</script>

Thanks for the great tool! And for the good idea of overriding the method like that :)

jdempcy commented 1 year ago

Hey! Is it possible to disable console clearing?

@Valar353 You can do this by overriding console.clear().

jdempcy commented 1 year ago

@AEPKILL this question can be closed as there is a suitable workaround (imo)

jdempcy commented 1 year ago

Note that pointing to void did not work for me and I actually had to override to an empty function with () => {}.