JavaScript to Base64
Encode JavaScript to Base64 data URIs or decode Base64 scripts safely.
JavaScript to Base64 Encoder and Decoder
Encode JavaScript source code to Base64 or a data:text/javascript;base64,... URI, and decode Base64-encoded scripts back to readable code. The conversion is UTF-8 safe, so string literals with emoji or non-English text survive the round trip.
Loading a script from a data URI
With Output as data URI enabled you can load code without a separate file:
<script src="data:text/javascript;base64,Y29uc29sZS5sb2coMSk="></script>
That URI contains console.log(1). The same works for ES modules with import "data:text/javascript;base64,..." and for web workers created from a data URL. It's convenient for demos, self-contained HTML files, test harnesses, and generated reports.
Bookmarklets and snippets
Bookmarklets are small scripts saved as bookmarks. Complex ones break easily because of quotes, % characters, and line breaks. A robust pattern is to encode the code and run it with javascript:eval(atob('...')), though atob() only returns Latin-1, so keep such snippets ASCII or decode with TextDecoder. Base64 is also common when passing scripts through JSON APIs, CI variables, or browser automation tools like Playwright and Selenium.
Content Security Policy
Sites with a strict CSP will refuse data: scripts unless script-src explicitly allows data:, and allowing it is considered unsafe because an attacker who can inject markup could then execute arbitrary code. For production pages, serve scripts as files or use nonces and hashes.
Obfuscation is not security
Encoding code does not hide it. Browsers decode the data URI and show the real script in dev tools, and anyone can paste it into Base64 to JavaScript on this page. Minification and obfuscators only slow readers down as well. Keep secrets on the server. Conversely, when you find eval(atob(...)) in a suspicious plugin or email attachment, decoding it here is a safe way to inspect the payload without executing it. For string-level escaping use JavaScript Escape / Unescape, and for stylesheets see CSS to Base64.
Frequently Asked Questions
Does Base64 hide or protect my JavaScript?
No. Base64 is not obfuscation and certainly not security. Anyone can decode it in a second, and browser dev tools show the decoded script anyway. Never put API keys or secrets in client-side code, encoded or not.
Why is my data: script blocked?
A Content Security Policy with script-src that doesn't include data: blocks scripts loaded from data URIs. Adding data: to script-src is strongly discouraged because it lets injected content run code. Prefer serving the file or using a nonce or hash.
Why do security scanners flag Base64 JavaScript?
Malware often uses eval(atob('...')) to hide its payload from simple pattern matching. Legitimate code rarely needs this, so antivirus tools, WAFs, and code reviewers treat it as suspicious. Decode unknown strings here to see what they actually do before running anything.