JavaScript code obfuscator online: obfuscate JS locally
JavaScript code obfuscation online, your code stays local in the browser
- Free
- No account required
Warning. Obfuscation can discourage casual copying and increase reverse-engineering effort. The result is still client-side code that a user can inspect; it does not protect secrets, replace server-side authorization or fix security vulnerabilities.
These transforms are text heuristics, not a JavaScript parser: console calls inside an expression become void 0 instead of disappearing, and quotes in comments or regex literals can still be misread. The output may parse and still behave differently from the original, so test it before you ship it.
Before you download: do not put API keys, passwords or tokens in client code. Authorization and secrets belong on the backend, and obfuscation does not protect them.
A JavaScript code obfuscator online changes selected client-side patterns locally to make quick reading harder. It is not encryption and does not protect secrets, API keys or server authorization.
Why obfuscation is not encryption
Obfuscation buys time, not secrecy. It slows down a casual read in DevTools, but a determined reader will recover the logic, because deobfuscators are public and free.
Sensible uses: copying friction for a widget, a demo or front-end game logic, and more work for scrapers. Prices, coupons and API keys are still checked on the server.
Bad uses: hiding malware, dodging ad blockers, or hiding trackers from users.
Test behavior after transformation
Keep the original file and run tests on the output. Check error handling, console messages and calls from other scripts. Successfully generating code does not prove that the application behaves as before.
How to obfuscate JavaScript code before publishing
You obfuscate JavaScript last, on finished code, and only on files you wrote yourself. First make sure the code holds nothing that should stay on the server.
-
Remove secrets from client code
Move API keys, passwords and pricing rules to the server. Obfuscation is not encryption, and the browser has to read every string to run the code.
-
Pick the files you want to protect
Obfuscate your own logic, such as a widget or a demo. Leave third-party libraries and polyfills alone, because all you gain there is a bigger file.
-
Paste the code and choose the techniques
String encoding turns text into
\xand\usequences, and console removal cuts outconsole.*calls. Both transforms run locally in your browser. -
Test the output before you ship it
The tool uses text heuristics, not a parser. Run your tests or click through the main flows on the obfuscated code, and only then deploy it.
Example code before and after obfuscation
The examples show the transforms this tool performs.
const greeting = 'Hello';const greeting = '\x48\x65\x6c\x6c\x6f';The browser reads this as the same string, Hello. Typing the variable into the DevTools console shows the original value.
function save(data) {
console.log('saving', data);
return api.post(data);
}function save(data) {
return api.post(data);
}Logs with user data disappear from the production console, and the file gets a little smaller.
fetch('https://api.example.com/v1/data?key=SECRET_KEY');fetch('/api/data'); // the server adds the keyAn encoded key still shows up in the Network tab. The fix is to send the request through your own server, which adds the key on its side.
Common JavaScript obfuscation mistakes
-
Obfuscation instead of protecting secrets
The browser has to read every string in client code, so anyone who opens DevTools can read it too. Secrets belong on the server or in short-lived session tokens.
-
Obfuscating the whole bundle with its libraries
Libraries are public, so obfuscating them hides nothing, while the file grows and runs slower. The javascript-obfuscator authors also advise against obfuscating vendor scripts.
-
Publishing source maps with the code
A
.mapfile on the server lets DevTools show the source in its original form. If you want to make reading harder, do not publish production source maps. -
Shipping without a test
Text transforms can change how code behaves, for example a console call inside an expression turns into
void 0. Test obfuscated code like any other change. -
Heavy techniques in performance-critical code
Control flow flattening and similar techniques from dedicated obfuscators slow execution down. Keep them out of code that handles scrolling, animation or the first render.
JavaScript obfuscation in the documentation
| Value | What it means | Source |
|---|---|---|
| \xNN | A hex escape in a JavaScript string is exactly two hexadecimal digits for characters from 0x00 to 0xFF. The browser turns it back into a plain character when it parses the code. | MDN, Lexical grammar |
| 15 to 80% | How much slower obfuscated code runs according to the javascript-obfuscator documentation, depending on the options. | javascript-obfuscator, README |
| 1.5× | How much slower code can run after control flow flattening, according to the same documentation. | javascript-obfuscator, README |
| API keys | Google Cloud advises against putting API keys in client code and recommends passing requests through a server that adds the key. | Google Cloud, API keys best practices |
| pretty print | The Chrome DevTools Sources panel formats minified files by default, and with source maps it shows code in its original form. | Chrome DevTools, JavaScript reference |
Sources checked:
Obfuscation techniques
- MMangling
- Rename variables and functions to opaque ids (e.g. _0x4a2f). Bundlers and Terser do this; this tool leaves names as they are.
- SString encoding
- Strings as \x6a\x61\x6e (hex), so literal values are less obvious. This is the technique this tool applies.
- DDead code injection
- Inject never-run code to grow size and muddy control flow. Found in dedicated obfuscators.
- CFControl flow flattening
- Turn if/while into a switch and a state table, which can slow execution. Also a dedicated-obfuscator technique.
Paste JavaScript, choose string encoding or console removal, then copy or download the result. The obfuscation runs locally in your browser and makes quick reading harder; it is not encryption.
A JavaScript code obfuscator changes selected code patterns to make quick reading in the browser harder. It does not hide client-side code, protect API keys or replace server-side authorization and security controls.
Yes. This obfuscator runs in your browser and does not upload pasted code to CometWeb. The output remains client-side code, so anyone using the page can still inspect and analyze it.
No. Keys belong on the backend or as short-lived session tokens.
Small for the transforms in this tool: encoded strings are a little longer, and dropping console calls makes the file smaller. Heavier techniques in dedicated obfuscators, such as control flow flattening, can slow code down noticeably, so time it before you ship.
String encoding can be reversed, and client-side code can always be analyzed in the browser. This tool adds friction to quick reading; it is not encryption or secret protection.
Minification removes whitespace and comments to make a file smaller, while obfuscation changes code to make it harder to read. Minification usually shrinks a file, and obfuscation often makes it bigger.
No. Library code is public, so obfuscation hides nothing in it while adding size and slowing execution. The javascript-obfuscator documentation also recommends obfuscating only your own code.
Yes, if you publish them with the code. DevTools uses source maps to show the original source files, so a map generated before obfuscation undoes the whole effect. Keep production source maps off the public server.
What else might come in handy
File or code ready? Check the result on the live page
TLS, headers, cookies and exposure, with a score breakdown and a remediation plan.