Search code examples
javascriptreactjsnext.jsdevtoolsdisable

Disable-devtool in Next.js


I am currently building an app in Next.js and I want to disable opening devtools. I found a nice package on npm - Disable-devtool - npm link but the problem is that nextjs keeps throwing me ReferenceError: navigator is not defined. I tried to look into node_modules but didn't find any solution whatsoever, any help please?

Thank you ❤️


Solution

  • Try this:

        if (
            typeof window !== "undefined" &&
            typeof window.navigator !== "undefined" &&
            typeof navigator !== "undefined" &&
            navigator.userAgent
        ) {
            const disableDevtool = require("disable-devtool");
            disableDevtool();
        }