How to disable browser developer tools?

Javascript

Javascript Problem Overview


I'm developing a web application and since it has access to a database underneath, I require the ability to disable the developer tools from Safari, Chrome, Firefox and Internet Explorer and Firebug in Firefox and all similar applications. Is there a way to do this?

Note: The AJAX framework provided by the database requires that anything given to the database to be in web parameters that can be modified and that anything it returns be handled in JavaScript. Therefore when it returns a value like whether or not a user has access to a certain part of the website, it has to be handled in JavaScript, which developer tools can then access anyway. So this is required.

UPDATE: For those of you still thinking I'm making bad assumptions, I did ask the vendor. Below is their response:

Here are some suggestions for ways of mitigating the risk:

> 1) Use a javascript Obfuscator to obfuscate the code and only provide > the obfuscated version with the sold application; keep the non > obfuscated version for yourself to do edits. Here is an online > obfuscator: > https://stackoverflow.com/questions/194397/how-can-i-obfuscate-javascript > http://en.wikipedia.org/wiki/Obfuscated_code > http://javascriptobfuscator.com/default.aspx > > 2) Use a less descriptive name; maybe 'repeatedtasks.js' instead of > 'security.js' as 'security.js' will probably stand out more to anyone > looking through this type of information as something important.

Javascript Solutions


Solution 1 - Javascript

No you cannot do this.

The developer menu is on the client side and is provided by the user's browser.

Also the browser developer should have nothing to do with your server side database code, and if it does, you need some maaaaaajor restructuring.

Solution 2 - Javascript

If your framework requires that you do authorization in the client, then...

> You need to change your framework

When you put an application in the wild, where users that you don't trust can access it; you must draw a line in the sand.

  • Physical hardware that you own; and can lock behind a strong door. You can do anything you like here; this is a great place to keep your database, and to perform the authorization functions to decide who can do what with your database.
  • Everything else; Including browsers on client computers; mobile phones; Convenience Kiosks located in the lobby of your office. You cannot trust these! Ever! There's nothing you can do that means you can be totally sure that these machines aren't lying to cheat you and your customers out of money. You don't control it, so you can't ever hope to know what's going on.

Solution 3 - Javascript

In fact this is somehow possible (how-does-facebook-disable-developer-tools), but this is terribly bad idea for protecting your data. Attacker may always use some other (open, self written) engines that you don't have any control on. Even javascript obfuscation may only slow down a bit cracking of your app, but it also gives practically no security.

The only reasonable way to protect your data is to write secure code on server side. And remember, that if you allow someone to download some data, he can do with it whatever he wants.

Solution 4 - Javascript

There's no way your development environment is this brain-dead. It just can't be.

I strongly recommend emailing your boss with:

  • A demand for a week or two in the schedule for training / learning.
  • A demand for enough support tickets with your vendor to figure out how to perform server-side validation.
  • A clear warning that if the tool cannot do server-side validation, that you will be made fun of on the front page of the Wall Street Journal when your entire database is leaked / destroyed / etc.

Solution 5 - Javascript

No. It is not possible to disable the Developer Tools for your end users.

If your application is insecure if the user has access to developer tools, then it is just plain insecure.

Solution 6 - Javascript

Don't forget about tools like Fiddler. Where even if you lock down all the browsers' consoles, http requests can be modified on client, even if you go HTTPS. Fiddler can capture requests from browser, user can modify it and re-play with malicious input. Unless you secure your AJAX requests, but I'm not aware of a method how to do this.

Just don't trust any input you receive from any browser.

Solution 7 - Javascript

you cannot disable the developer tool. but you can annoys any one who try to use the developer tool on your site, try the javascript codes blow, the codes will break all the time.

    (function () {
        (function a() {
            try {
                (function b(i) {
                    if (('' + (i / i)).length !== 1 || i % 20 === 0) {
                        (function () { }).constructor('debugger')()
                    } else {
                        debugger
                    }
                    b(++i)
                }
                )(0)
            } catch (e) {
                setTimeout(a, 5000)
            }
        }
        )()
    }
    )();

Solution 8 - Javascript

Update at the time (2015) when this answer was posted, this trick was possible. Now (2017) browsers are mature. Following trick no longer works!

Yes it is possible. Chrome wraps all console code in

with ((console && console._commandLineAPI) || {}) {
  <code goes here>
}

... so the site redefines console._commandLineAPI to throw:

Object.defineProperty(console, '_commandLineAPI',
   { get : function() { throw 'Nooo!' } })

This is the main trick!

Solution 9 - Javascript

I found a way, you can use debugger keyword to stop page works when users open dev tools

(function(){
  debugger
}())

Solution 10 - Javascript

$('body').keydown(function(e) {
        if(e.which==123){
            e.preventDefault();
        }
        if(e.ctrlKey && e.shiftKey && e.which == 73){
            e.preventDefault();
        }
        if(e.ctrlKey && e.shiftKey && e.which == 75){
            e.preventDefault();
        }
        if(e.ctrlKey && e.shiftKey && e.which == 67){
            e.preventDefault();
        }
        if(e.ctrlKey && e.shiftKey && e.which == 74){
            e.preventDefault();
        }
    });
!function() {
        function detectDevTool(allow) {
            if(isNaN(+allow)) allow = 100;
            var start = +new Date();
            debugger;
            var end = +new Date();
            if(isNaN(start) || isNaN(end) || end - start > allow) {
                console.log('DEVTOOLS detected '+allow);
            }
        }
        if(window.attachEvent) {
            if (document.readyState === "complete" || document.readyState === "interactive") {
                detectDevTool();
              window.attachEvent('onresize', detectDevTool);
              window.attachEvent('onmousemove', detectDevTool);
              window.attachEvent('onfocus', detectDevTool);
              window.attachEvent('onblur', detectDevTool);
            } else {
                setTimeout(argument.callee, 0);
            }
        } else {
            window.addEventListener('load', detectDevTool);
            window.addEventListener('resize', detectDevTool);
            window.addEventListener('mousemove', detectDevTool);
            window.addEventListener('focus', detectDevTool);
            window.addEventListener('blur', detectDevTool);
        }
    }();

Solution 11 - Javascript

Yeah, this is a horrible design and you can't disable developer tools. Your client side UI should be sitting on top of a rest api that's designed in such a way that a user can't modify anything that was already valid input anyways.

You need server side validation on inputs. Server side validation doesn't have to be verbose and rich, just complete.

So for example, client side you might have a ui to show required fields etc. But server side you can just have one boolean set to true, and set it to false if a field fails validation and then reject the whole request.

Additionally your client side app should be authenticated. You can do that 100 thousand ways. But one I like to do is use ADFS passthrough authentication. They log into the site via adfs which generates them a session cookie. That session cookie get's passed to the rest api (all on the same domain) and we authenticate requests to the rest api via that session cookie. That way, no one that hasn't logged in via the login window can call the rest api. It can only be called form their browser context.

Developer tool wise, you need to design your app in such a way that anything that a user can do in the developer console is just a (feature) or a breaking thing. I.e. say they fill out all the fields with a js snippet, doesn't matter, that's valid input. Say they override the script and try to send bad data to the api calls. Doesn't matter, your server side validation will reject any bad input.

So basically, design your app in such a way that developer tool muckery either brakes their experience (as it won't work), or lets them make their lives a little easier, like auto selecting their country every time.

Additionally, you're not even considering extensions... Extensions can do anything and everything the developer console can do....

Solution 12 - Javascript

You can not block developer tools, but you can try to stop the user to enter them. You can try to customize a right-click menu and block the keystrokes for developer tools.

Solution 13 - Javascript

Yes. No one can control client browser or disable developer tool or debugger tool.

But you can build desktop application with electron.js where you can launch your website. Where you can stop debugger or developer tool.

Our team snippetbucket.com had build plenty of solution with electron.js, where similar requirement was their. as well restructure and protect website with many tools.

As well with electron.js many web solution converted and protected in well manner.

Solution 14 - Javascript

https://github.com/theajack/disable-devtool

This tool just disabled devtools by detecting if its open and then just closing window ! Very nice alternative. Cudos to creator.

Solution 15 - Javascript

You can easily disable Developer tools by defining this:

Object.defineProperty(console, '_commandLineAPI', { get : function() { throw 'Nooo!' } })

Have found it here: https://stackoverflow.com/questions/21692646/how-does-facebook-disable-the-browsers-integrated-developer-tools

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBrandonView Question on Stackoverflow
Solution 1 - JavascriptNaftaliView Answer on Stackoverflow
Solution 2 - JavascriptSingleNegationEliminationView Answer on Stackoverflow
Solution 3 - JavascriptLiberat0rView Answer on Stackoverflow
Solution 4 - JavascriptsarnoldView Answer on Stackoverflow
Solution 5 - JavascriptJustin NiessnerView Answer on Stackoverflow
Solution 6 - JavascripttrailmaxView Answer on Stackoverflow
Solution 7 - JavascriptNerdroidView Answer on Stackoverflow
Solution 8 - JavascriptmumairView Answer on Stackoverflow
Solution 9 - JavascriptnuclearView Answer on Stackoverflow
Solution 10 - JavascriptDoston UsmonovView Answer on Stackoverflow
Solution 11 - JavascriptRyan MannView Answer on Stackoverflow
Solution 12 - JavascriptGreenView Answer on Stackoverflow
Solution 13 - JavascriptTejas TankView Answer on Stackoverflow
Solution 14 - JavascriptPaulius GreičiūnasView Answer on Stackoverflow
Solution 15 - JavascriptNicholas ValbusaView Answer on Stackoverflow