简体   繁体   中英

How can I make my JavaScript code un-readable in the developer console?

I'm trying to find a way to make my JavaScript code invisible in the browser's developer console, but still usable. If that's not possible, I need a way to make it runable only on a specific website. Thanks in advance.

Internet Site

For a public website , what you want isn't possible. You can obfuscate the code, but you cannot make it invisible, as the browser is under the user's control and the browser needs the code to execute it, so the user can always force the browser to reveal the code.

Of course you could make the obfuscation more elaborate than just an uglification, thereby getting into DRM topics. But that still wouldn't keep anyone getting hold of the (obfuscated) script to still run it, and possibly reverse-engineer it.

As JavaScript code is running on your users' machines, they have to trust it. (To some extend. It runs sandboxed in the JavaScript runtime, so it can't do too much harm.) Obfuscating the code beyond minification will make you look very suspicious, as it'd suggest you have to hide functionality that'd hurt your users or their machine.

So as others have already commented, code that has to be secret will have to be run server-side only, so that only the results will reach the client.

Controlled Environment

It's different in an intranet scenario where the respective IT department might have exclusive control over both, the intranet server and the client computers. There, the IT department could just disable inspection features of the installed browsers. Additionally they would have to make sure that the user has no ability to otherwise download the script or to scrape it from the browser cache.

Effectively, this would require computers set up to be used as web kiosks (web terminals without the ability to run arbitrary programs), only. Off course, the network or the intranet server would have to reliably authenticate these trusted client machines, or someone could just bring and plug in their own machine to get the JavaScript code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM