Encoding is not encryption
This tool wraps your script in Base64 and evaluates it at runtime. Base64, defined in RFC 4648, is a way of representing bytes as text, not a cipher. Anyone can reverse it with atob() in the browser console, or by replacing eval with console.log, and see the original source with every comment and variable name intact.
That makes it useful for keeping code from being read at a glance or copied by accident, and for getting a snippet past systems that mangle certain characters. It does not protect secrets. Any API key, password or business rule shipped to the browser can be recovered by a determined person, whatever obfuscation is applied. Keep sensitive logic and credentials on a server.
Worked example: what happens to the sample script
The default sample is a 143-character function that calculates a price with tax and logs calculateTotal(100, 18), which prints 118. The source is first encoded as UTF-8 bytes, so accented letters and emoji survive, and Base64 turns every 3 bytes into 4 characters, giving a 192-character payload. With the decoder around it, the output is 291 characters, about twice the original size.
The decoded code runs through indirect eval, written (0,eval)(...), which evaluates it in the global scope rather than inside a function. In the example, calculateTotal is still a global function, so other scripts and an inline onclick="calculateTotal()" attribute can call it as before. The same applies to top-level var declarations. Top-level let, const and class declarations are the exception: eval gives them their own scope, so attach anything that must be shared to window explicitly.
Practical limits of eval-based wrappers
Before using the output on a real site, check these constraints:
- A Content Security Policy without 'unsafe-eval' blocks eval, and the script will fail with a CSP error. Many security-conscious sites and some hosting platforms set such a policy.
- ES module syntax (import and export statements) cannot run inside eval, because eval parses its input as a classic script.
- Error stack traces point to the eval call rather than your original line numbers, which makes production debugging harder.
- The output grows by at least a third and cannot be minified further, so it costs more bandwidth than the original.
Alternatives for real-world protection and size
If the goal is smaller, faster code, use a minifier such as Terser or esbuild. They shorten variable names, remove whitespace and comments, and drop dead code, which makes the output both smaller and harder to read, with source maps available for debugging.
If the goal is to make reverse engineering slower, dedicated obfuscators rename identifiers, encode strings into lookup arrays and restructure control flow. They raise the effort required but still cannot make client-side code secret, and heavy settings can slow execution noticeably. For licence checks, pricing rules or anything that must not be bypassed, move the logic behind an API.
The Beautify mode first unpacks this tool's own Base64 wrapper if it finds one, then re-indents the code. It breaks lines after braces and statement-ending semicolons while skipping strings, template literals, comments, regular expressions and the inside of parentheses, so for loop headers and string contents are left intact. It does not add spaces around operators or rewrap long lines, and it puts object literals on several lines, so for consistent house style run the result through Prettier or your editor's formatter.
JS Obfuscator & Beautifier: frequently asked questions
Can obfuscated JavaScript be reversed?
Yes, always. The browser must be able to run the code, so the original logic is recoverable. Simple encoding like Base64 is reversed in seconds, while advanced obfuscation can take longer to untangle but never makes the code secret.
Does obfuscation hurt performance?
Encoding with an eval wrapper adds a decode step and prevents some engine optimisations at load time, though for small scripts the difference is minor. Heavy obfuscation techniques such as control-flow flattening can slow hot code paths considerably.
Is it safe to put an API key in obfuscated JavaScript?
No. Anyone can watch network requests in developer tools and see the key being sent, regardless of how the code is written. Use a server-side proxy or restrict the key by domain and permissions on the provider's side.
What is the difference between minification and obfuscation?
Minification aims to reduce file size while keeping behaviour identical, and its unreadability is a side effect. Obfuscation aims to make code hard to understand, often at the cost of larger files and slower execution. Production builds almost always minify; obfuscation is an extra, optional step.
Why does my site show a Content Security Policy error after using the wrapper?
The wrapper relies on eval, which a policy without 'unsafe-eval' in script-src refuses to run. Either serve the original or minified script instead, or relax the policy, though allowing eval weakens protection against injected scripts.