-2

I'm making a game and I want to prevent anyone doing Inspect Element(right click, developer tools, etc) using Javascript.

I tried

oncontextmenu='return false'

but ctrl + shift + I or ctrl + shift + J or ctrl + shift + C or developer tools still allows inspect.

  • not gonna happen, nope nope nope. You can not disable it. – epascarello Nov 18 '22 at 15:40
  • https://stackoverflow.com/questions/28690564/is-it-possible-to-remove-inspect-element – john Smith Nov 18 '22 at 15:41
  • maybe helpful https://github.com/sindresorhus/devtools-detect – john Smith Nov 18 '22 at 15:44
  • There are obnoxious solutions that try to do something akin to `eval("debugger;")` and then try to measure the time it takes to run this, asynchronously. If the dev tools are not open, this statement does nothing, so it takes little more than 0 ms; otherwise, it takes more time. Those solutions then clear the console and refresh the site, making usage of dev tools impossible. But scripts that do this can still be blocked using ad blockers or userscript managers. – Sebastian Simon Nov 18 '22 at 17:38

1 Answers1

-3

You can't, but this will block right click:

document.addEventListener("contextmenu", (e) => {
  e.preventDefault();
});
dezman
  • 18,087
  • 10
  • 53
  • 91