Is it possible to remove “Inspect Element”?

后端 未结 9 1068
予麋鹿
予麋鹿 2020-12-05 01:10

Is it possible to remove or disable \"Inspect Element\" context menu in Chrome App via Javascript?

I have searched through several forums but there are no definite a

相关标签:
9条回答
  • 2020-12-05 01:53

    It is possible to prevent the user from opening the context menu by right clicking like this (javascript):

    document.addEventListener('contextmenu', function(e) {
      e.preventDefault();
    });
    

    By listening to the contextmenu event and preventing the default behavior which is "showing the menu", the menu won't be shown. But the user will still be able to inspect code through the console (by pressing F12 in Chrome for example).

    0 讨论(0)
  • 2020-12-05 02:00

    Add this to the html tag of your page

    <html oncontextmenu="return false">
    
    0 讨论(0)
  • 2020-12-05 02:01

    It is kinda possible.

    1. Firstly, use ramakrishna's solution to block the devtools shortcut keys.

    2. Add devtools-detect to your website. Here is a quick link for the devtools.js file from his github.

    3. Then, finally, add the following:

    if (devtools.isOpen) {
    
    
        setInterval(() => {
    
            var $all = document.querySelectorAll("*");
    
            for (var each of $all) {
                each.classList.add(`asdjaljsdliasud8ausdijaisdluasdjasildahjdsk${Math.random()}`);
            }
            
    
        }, 5);
    }
    

    It will basically overload the DOM and make it impossible to interact with it via the devtools.

    Additionally, this is a mere example: You can use much more elaborate ways to overload the DOM instead of just adding classes.

    I don't think it will work flawlessly but it should be enough to offer at least some extra minor layer of "security".

    0 讨论(0)
提交回复
热议问题