0

I'm trying to control the commands that are executed in console so you can't acces some basic commands if you're the client.

I've tried to delete all the console using console = {}, but it only deletes the console commands.

  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Apr 16 '23 at 21:23

1 Answers1

0
  1. Generally, that's impossible. A programmer can easily pause your JS code in any point and take out all the values and functions they could want.

  2. If you want script-kiddies and browser extensions to not have acess to your classes and variables, don't place them in global (window) scope.
    If you write

var a = 123;
let b = 'asd'
class C {}

then they exist in global scope and can be acessed as

window.a
window.b
window.C

To prevent that you should either scope them

function f(){
  var a = 123;
  let b = 'asd'
  class C {}
}
f();
// no references here

or use <script type="module"> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules

  1. If you MUST disallow acess to your things in every way possible, you can compile your code in C/C++/Rust/whatever into WebAssembly. That's not an easy task. Anyways, user can do anything with JS, web connection, etc.
Dimava
  • 7,654
  • 1
  • 9
  • 24