JavaScript Obfuscator

Obfuscate JavaScript so it is hard to read or copy: renamed variables, encoded strings and scrambled control flow.

Runs in your browser. Nothing is uploaded.

How to use the JavaScript Obfuscator

  1. Paste JavaScript into the left box, open a .js file, or press Load example.
  2. Choose a Strength and where the code will run.
  3. List any names other scripts call under Names to keep.
  4. Copy or download the obfuscated code, then test it before you use it.

Make JavaScript hard to read

JavaScript is delivered to the browser as source code, so anyone can open developer tools and read it. Minifying makes it shorter but the logic is still easy to follow once it is reformatted. Obfuscation goes further: it rewrites the code so that it does the same thing but is very hard for a person to understand. That can discourage people from copying a widget, lifting a game’s logic or casually tampering with a calculation.

This page runs javascript-obfuscator in your browser.

Strength

  • Low renames variables and functions to meaningless hexadecimal names and moves strings into a shuffled table. It is fast and adds little size.
  • Medium also encodes the string table, splits long strings, turns numbers into expressions, flattens control flow so the order of operations is hidden, and adds dead code.
  • High applies everything at full strength with stronger string encoding. Expect a much larger and slower file; use it for small, sensitive pieces of logic rather than whole applications.

Other options

  • Runs in: choose Browser, no eval if your site has a strict Content Security Policy, or Node.js for server code.
  • Names to keep: functions or variables that HTML attributes or other scripts call by name, for example initWidget.
  • Rename global names also renames top-level names, which breaks anything outside the file that uses them.
  • Silence console replaces console methods so nothing is logged.
  • Self-defending breaks the code if it is reformatted.

Limits

Obfuscation is a deterrent, not protection. A determined person can still work out what the code does, so anything that must stay secret, such as API keys, prices you enforce or licence checks that matter, belongs on a server. Also keep your original source: obfuscated code can’t be turned back into it.

Private

Your code is processed on your device and never uploaded.

Frequently asked questions

Does obfuscation make my code secure?

No. It makes code much harder to read and copy, but anything that runs in a browser can be studied by someone determined enough. Never put passwords, API keys or other secrets in client-side code, obfuscated or not.

Will the obfuscated code still work?

It is designed to behave exactly like the original, but always test it. Code that other scripts call by name needs those names kept, and very dynamic code may need the Low setting.

Why is the result so much bigger?

Obfuscation adds machinery: an encoded string table, helper functions, dummy code and scrambled control flow. High strength can make a file several times larger and noticeably slower.

What does Self-defending do?

It makes the code stop working if someone reformats it, which slows down people trying to read it with a formatter. Don't use it if you minify or process the file again afterwards.

Which library does this use?

javascript-obfuscator, an open-source obfuscator, running entirely in your browser. Your code is never uploaded.

Tutorials