nemrod.se Various guides and experiments

Disable F12 from opening the Developer Console in Chrome


F12 keyLinus Torvalds made a post on Google+ asking if there was a convenient way of disabling F12 from opening the developer console in Chrome (because apparently he’s “totally spastic and uncontrolled” when going for backspace ;)).

I, of course, had to oblige by creating a Chrome extension: Disable F12 on Chrome Web Store

It can access “your data on all websites” because it needs to inject a JavaScript that captures the F12 keypress and prevents the event from going any further. You can inspect the code in the extension yourself but if you can’t be bothered here it is:

manifest.json

{
	"name": "Disable F12",
	"version": "1.0",
	"description": "An extension to disable F12 opening the dev console.",
	"icons": { "128": "icon128.png" },
	"content_scripts": [
		{
			"matches": ["*://*/*"],
			"js": ["disablef12.js"]
		}
	]
}

disablef12.js

window.addEventListener("keydown", keyListener, false);

function keyListener(e) {
	if(e.keyCode == 123) {
		e.returnValue = false;
	}
}

Posted in Chrome Extensions | 9 Comments

9 responses to “Disable F12 from opening the Developer Console in Chrome”

  1. Ian Kelling says:

    I installed your extension and F12 still opens the console every time. Any help you can offer? Chrome 18.0.1025.151 m.

  2. Ian Kelling says:

    Actually, I enabled the option to work in incognito mode and now it works fine.

  3. Ian Kelling says:

    Even though I was not in inconito mode.

  4. YOUNGSTER says:

    i have an easy idea.
    step1:- simply download & add firebug lite from chrome web store.

    step2:- by clicking on firebug lite, enable firebug.

    step3:- now press the button F12.

    now you see that chrome console has not opening but the firebug lite has open.

    to throw this problem.

    step4:- simply click again on firebug lite.

    now when you want firebug open. firebug is very trustable.

  5. Lectrik says:

    Worked perfectly, needed this for a kiosk wayfinder! BTW it won’t work until your restart Chrome if you were trying it immediately after installing the extension.
    Thank you!

  6. Rob says:

    I understand that this thread it old but I found the ext via search engine and installed it…..however.
    Not sure when this stopped working but I installed it recently and it’s useless, does not work at all!!!

  7. nemrod says:

    Hi Rob,
    Not sure what to tell you—it works just fine for me. Make sure you’re in a new tab created after enabling the extension when trying it, and IIRC it doesn’t work in chrome internal pages (i.e. chrome:// URLs). Might be it doesn’t work on some configuration of browser and operating system that I haven’t tested. Could be an isolated site as well, so check other sites to make sure.

  8. Simon Zerafa says:

    Hi,

    Can this be extended to also block CTRL+SHIFT+I as this also allows access to the Developer Tools.

    An option to not display the extension icon in the toolbar would also be useful.

    Kind Regards

    Simon Zerafa

  9. nemrod says:

    Hi Simon,
    I imagine it would work, you’d just need to add some logic to listen for the combination in the listener. I don’t have time to fiddle with it at the moment though. As to the icon, as far as I can remember Chrome displays all icons by default since version 49 or some such. You can hide it yourself though, putting in nearest the omnibox and dragging it to hide.

Leave a Reply

Your email address will not be published. Required fields are marked *