Skip to content

Instantly share code, notes, and snippets.

@yajd
Created February 19, 2014 02:43
Show Gist options
  • Save yajd/9085126 to your computer and use it in GitHub Desktop.
Save yajd/9085126 to your computer and use it in GitHub Desktop.
ff-addon-script: Use atob and btoa in privelaged scope (no access to window)
const {utils: Cu} = Components;
const { atob, btoa } = Cu.import("resource://gre/modules/Services.jsm");
//can now use atob and btoa freely
//if it is utf-8 then do the following:
function atobUTF8(data) {
return decodeURIComponent(escape(atob(data)))
}
function btoaUTF8(data) {
return btoa(unescape(encodeURIComponent(data)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment