11

Is there a way to disable inspect element, right click and F12 in google chrome?

Konrad Dzwinel
  • 36,825
  • 12
  • 98
  • 105
User2364902
  • 431
  • 2
  • 4
  • 14

2 Answers2

26

This is definitely not possible to do from a web page.

Even if you disable right click and disable the default behaviors for F12, Ctrl+Shift+I, and Ctrl+Shift+J, there is no way to stop a user from opening Dev Tools on a different page and navigating to your page with Dev Tools already open.

Also, you can access Dev Tools by going to Menu > Tools > Developer tools, which cannot be prevented by any website.

apsillers
  • 112,806
  • 17
  • 235
  • 239
  • 2
    yeah in-order to prevent the right-click & F12 i used added this code to my DOM window.oncontextmenu = function () { return false; } document.onkeydown = function (e) { if (window.event.keyCode == 123 || e.button==2) return false; } – User2364902 Dec 18 '13 at 15:13
  • What an absolute statement to make. It is possible, one just have to think hard enough. – mjs Aug 10 '16 at 17:26
  • @momomo If you have thought of way that it is possible, please feel free to post an additional answer. – apsillers Aug 10 '16 at 17:38
  • Yes, and it works. Let's just say the question is how much one is willing to destroy the user experience and how much it is worth to keep them out. I am not going to into great details because it is not in my interest for everyone to start doing that, which will likely become a big enough answer making my life more and more difficult when I start inspecting other sites in the future. But for my site, I want to keep them out ;) – mjs Aug 10 '16 at 18:04
  • @apsillers Think harder. The detection of the dev tools opening is not the question here. That is already possible using various tricks. Once detected there are a number of things one can do. – mjs Aug 10 '16 at 19:26
  • @momomo I think there are always ways to open (or keep open) Dev Tools that are undetectable to the page. That appears to be our fundamental disagreement. I have been not been able to think of a way to detect Dev Tools opening by (1) setting dev tools to open a new window instead of a sidecar in-window style, (2) clicking on your page's address bar, and (3) pressing `Ctrl+Shift+I`. (In Chrome, there will always be an address bar.) You can get a `blur` event on the window (only the *first* time, if Dev Tools is not already open, indistinguishable from any other loss of focus). – apsillers Aug 10 '16 at 19:36
  • @momomo So, I guess if you goal is "completely destroy the page every time it loses focus" you can do that, which would make use Dev Tools hard; I agree. (Not 100% convinced it's impossible, though, since `blur` is a bit finicky.) – apsillers Aug 10 '16 at 19:38
  • @apsillers Have you tried opening the dev tools on facebook? – mjs Aug 10 '16 at 19:46
  • Are you thinking of this? http://stackoverflow.com/questions/21692646/how-does-facebook-disable-the-browsers-integrated-developer-tools This takes advantage of specific environment states that exist in console code (and may not work anymore?). This doesn't detect or disable dev tools as a whole (notably Inspect, Network, etc) – apsillers Aug 10 '16 at 19:55
  • No, not thinking of that question. That talks about disabling it in a different way than what I am suggesting. Mine is bullet proof provided of course that you can detect inspector tools, and doesn't disable it per se, but makes it useless and inaccessible. – mjs Aug 10 '16 at 20:27
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/120642/discussion-between-apsillers-and-momomo). – apsillers Aug 10 '16 at 21:44
  • @User2364902 Check out my answer. – Praveen Kumar Purushothaman Jun 05 '20 at 10:20
0

You can run chromium in a java environment. This I have seen, then its impossible to open developer tools, and settings etc are not accessable. But of course it would involve a lot more work and development time.