The global atob method can be used to decode base64 strings (and btoa can be used to encode a string as base64). After decoding, the eval string can be used to parse the string as code and run it.
For example, here is a single-line font for printing the identifier of the current extension:
alert(eval(atob('Y2hyb21lLmkxOG4uZ2V0TWVzc2FnZSgnQEBleHRlbnNpb25faWQnKQ==')));
Explanation
I generated the previous base64 line by typing btoa("chrome.i18n.getMessage('@@extension_id')") in the JavaScript console. You can use any other method (e.g. base64 command ). Here's a complete breakdown of the previous single-line file.
alert(eval(atob(btoa("chrome.i18n.getMessage('@@extension_id')")));
Content Security Policy
If you want to use this method in the extension process (for example, background / popup ), you need to adjust the Content Security Policy . By default, code generation from strings is prohibited. To override this default policy, add the following entry to the manifest file:
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
Rob w source share