💻 What Does This Script Do?
This script blocks:
- Right-click (context menu)
- Keyboard shortcuts: F12, Ctrl+Shift+I/J, Ctrl+U
- Access to DevTools via console or window dimension changes
⚠️ Disadvantages of Using This Approach
- It can annoy users by blocking normal browser functionality.
- May interfere with accessibility tools or extensions.
- Not foolproof – experienced users can easily bypass it.
- Redirecting users to a blank page without explanation can damage trust.
📜 The JavaScript Code
document.addEventListener('contextmenu', function (e) {
e.preventDefault();
});
document.addEventListener('keydown', function (e) {
if (
e.key === 'F12' ||
(e.ctrlKey && e.shiftKey && (e.key === 'I' || e.key === 'J')) ||
(e.ctrlKey && e.key === 'U')
) {
e.preventDefault();
alert("Developer tools detected! Closing the page.");
redirectToBlank();
}
});
function redirectToBlank() {
window.location.replace("about:blank");
}
(function detectDevTools() {
let devtoolsOpen = false;
function checkWindowSize() {
const threshold = 160;
if (window.outerWidth - window.innerWidth > threshold || window.outerHeight - window.innerHeight > threshold) {
devtoolsOpen = true;
}
}
function checkConsoleBehavior() {
const element = new Image();
Object.defineProperty(element, 'id', {
get: function () {
devtoolsOpen = true;
alert("Developer tools detected! Closing the page.");
redirectToBlank();
}
});
console.log(element);
}
function monitorDevTools() {
devtoolsOpen = false;
checkWindowSize();
if (devtoolsOpen) {
alert("Developer tools detected! Closing the page.");
redirectToBlank();
} else {
checkConsoleBehavior();
}
}
setInterval(monitorDevTools, 100);
})();