Avatar ·

How does Facebook disable built-in developer tools in the browser?

Hi everyone! I'm a beginner web developer and recently noticed strange behavior on the Facebook website. When I open the developer console (F12) in Chrome or Firefox, the site behaves unusually: the page freezes, warnings appear, and sometimes the console just clears itself. I've heard that Facebook uses some methods to protect against hacking and prevent attackers from using DevTools.\n\nI became curious about how this works technically. I tried writing a simple script that would detect whether the console is open, but I didn't succeed:\n\n```javascript\n// My failed attempt\nwindow.addEventListener('resize', function() {\n if (window.outerHeight - window.innerHeight > 100) {\n console.log('Console is open!');\n }\n});\n```\n\nThis code only triggers when