DEV Community

Cover image for Disable opening dev console in browser using javascript
Rahul kumar
Rahul kumar

Posted on

Disable opening dev console in browser using javascript

How to disable opening dev console in browser

In order to disable dev console in browser, you need to disable two things.

  1. Right click
  2. ctrl+shift+I

Disable right click

document.addEventListener('contextmenu', event => event.preventDefault());
Enter fullscreen mode Exit fullscreen mode

For more info visit

Disable ctrl+shift+I

document.body.addEventListener("keydown", (e) => {
            if(e.ctrlKey && e.shiftKey && e.key == "I")
                e.preventDefault();
        })
Enter fullscreen mode Exit fullscreen mode

For more info visit

Note:

There is still some ways to get around this technique and user can open dev console on your website, can you guess what it is?

Top comments (7)

Collapse
 
keogami profile image
keogami

1) Disabling right click is a sin, and whoever does it will reserve their place in hell.

2) why would you need to disable opening dev console?

Collapse
 
grahamthedev profile image
GrahamTheDev

People think doing this coupled with disabling selecting text (the 2nd deadly sin) protects their content...I am not sure who told people that though 😂

Collapse
 
ats1999 profile image
Rahul kumar

Offcource, it can prevent this some extent.

Collapse
 
ats1999 profile image
Rahul kumar

Disabling dev console can prevent users from reading url of some static resources. This method will work for users who don't have much patience or who don't know how can bypass this method.

Collapse
 
ats1999 profile image
Rahul kumar

If we are developing a website for online exam, then disabling right click (context menu) would prevent user to do copy paste.

Collapse
 
tw2113 profile image
Michael Beckwith • Edited

Disable javascript in browser

Use your browser menus to open the tools as well.

Collapse
 
ats1999 profile image
Rahul kumar

yeah, we can also open website after opening dev console.