Tip: Calling window.atob() and btoa() from Jetpack-SDK
window.atob() decodes Base64 string, and window.btoa() encodes to Base64 string. These functions are not global functions but DOM Window's methods.
MDC page said as follows:
atob() is also available to XPCOM components implemented in JavaScript, even though window is not the global object in components.
But atob() seems to be implemented in only nsIDOMWindowInternal (i.e. DOM Window.) I could not find for atob() function in any other XPCOM components.
I think a certain DOM Window instance must be required. So I write following code for encode/decode Base64 text from Jetpack-SDK:
let win = require("window-utils").windowIterator().next());
let {Cc, Ci} = require("chrome");
let atob = win.QueryInterface(Ci.nsIDOMWindowInternal).atob;
return atob(v);
Note that require("window-utils").windowIterator() returns a iterator and calling next() function returns first element (window instance) of the iterator.