I’m sorry. For some reason I was under the impression that you need an URI for tab.attach()
. It should work to use the contentScript
option as a plain string, without the base64 encoding (which is not random :D):
const File = require("sdk/io/file");
// ...
const path = '...'; // not sure if forward / backward slashes matter
if (!File.exists(path)) { throw new Error(`Couldn't find the file "${ path }"`); }
const file = File.read(path, ''); // encoding, non-binary, i.e. text. Encoding should default to utf8, but you should test it if it matters
// now attach `file`:
tab.attach({ contentScript: file, });