Preloader
Javascript
  • Estimated reading time: 1 Minute

How to prevent regular users from opening the chrome developer tools in the browser with JavaScript

You can't prevent users from opening the developer's tools in the browser, that's for sure. At the end of all, they will be able always to open it through the settings of the browser and selecting Developer Tools. 

There was an interesting discussion about this in 2014 as Facebook was able to block totally the developer's tool window when the user opened it. Although they achieve it, this was patched in every browser after a while as the developer shouldn't be able to disable this window. 

However, you can of course block most of the default ways to open it. These default ways are:

  • Through the context menu in the browser (when doing right-click over the document).
  • Through the keyboard shortcut (Ctrl + Shift + I).

If you are still interested in blocking the mentioned features, then the following JavaScript snippet will do the trick:

window.oncontextmenu = function () {
    return false;
};

document.addEventListener("keydown", function(event){
    var key = event.key || event.keyCode;

    if (key == 123) {
        return false;
    } else if ((event.ctrlKey && event.shiftKey && key == 73) || (event.ctrlKey && event.shiftKey && key == 74)) {
        return false;
    }
}, false);

What this script does first is to disable the context menu of the browser with the first function. Then, an event listener is attached to the document, so when the user presses a special key, specifically the required combination to show the developer tools through the keyboard shortcut (Ctrl + Shift + I), it will do nothing.

Happy coding ❤️!

Share:
Carlos Delgado

Carlos Delgado

Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Related articles
JavaScript vs. Python for Data Analysis: Key Differences
30 Jan, 2026
  • Estimated reading time: 5 Minutes
Is Framevuerk Still Relevant in 2026?
3 Jan, 2026
  • Estimated reading time: 5 Minutes
The Best JavaScript i18n Libraries Compared
31 Oct, 2025
  • Estimated reading time: 8 Minutes
How to Build a Simple Photo Editor in the Browser with JavaScript
14 Sep, 2025
  • Estimated reading time: 5 Minutes
Weekly trending
What Makes a Portable Power Station Worth the Investment?
17 Jun, 2026
  • Estimated reading time: 4 Minutes
Building a Modern Lead Generation Workflow With Public Social Data
17 Jun, 2026
  • Estimated reading time: 3 Minutes
Best Instant Crypto Exchange for Lazy Investors
17 Jun, 2026
  • Estimated reading time: 6 Minutes
Our Sponsors

Our blog is proudly supported by industry-leading sponsors.