Question

Following OS.file example it uses TextEncoder however from bootstrap scope this is not available.

https://developer.mozilla.org/en-US/docs/JavaScript_OS.File/OS.File_for_the_main_thread#Example.3A_Read_the_contents_of_a_file_as_text

Only way I could access it is by going decoder = new Services.appShell.hiddenDOMWindow.TextDecoder(); but is thi the only way?

Was it helpful?

Solution

You can use TextEncoder and friends inside a javascript module. But doing so might be an overkill, if all you want is a couple of missing globals (putting aside the fact that jsm are cached and this might not work well with a restartless addon).

Conveniently Addon SDK's loader delivers what you need.

const { TextDecoder, TextEncoder } = Cu.import('resource://gre/modules/commonjs/toolkit/loader.js', {});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top