Completely Block Developer Tools in Your Web Application

By | May 4, 2021

You may want to prevent the user of your web application from debugging your website. Specifically, the user should not access browser developer tools by pressing F12 or Ctrl+Shift+J or by clicking on the customize and control > more tools > developer tools. To accomplish this, you can use the following ready-to-use JavaScript code.

Method 1: Only when the console is opened, the console print method will be executed.

// For Chrome version 73 and later
let num = 0;
    var devtools = new Date();
    devtools.toString = function() {
        num++;
        if (num > 1) {
            window.location.href = "https://www.itqit.com/404.html"
            blast();
        }
    }
    console.log('', devtools);

Method 2: When Chrome opens the console, it will read all the id elements on the page.

// Only for Chrome version 72 and earlier
var im = new Image();
    Object.defineProperty(im, 'id', {
        get: function() {
            window.location.href = "http://www.itqit.com/404.html"
            blast();
        }
    });
    console.log(im);