Is it possible to remove “Inspect Element”?

后端 未结 9 1141
予麋鹿
予麋鹿 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 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".

提交回复
热议问题