How to export a function to the global scope of a third party script?

Hello,

I’m trying to write an addon that depends on a third party library. That third party library depends on TextEncoder/TextDecoder interfaces, which should normally be available in the window object but it doesn’t exist in the external library context.

I can import them in my main.js:

var {Cu} = require('chrome');
Cu.importGlobalProperties(['TextDecoder']);

var fctX = require('./lib/libA').fctX;

But how does I make it accessible to the global scope of my libA.js without modifying the library itself?

Rather than try some very funky manipulation of the javascript context, try this: