Accesing page script and variables through contentScript

For the addon I am working on I need to inject some Javascript into the webpage. Currently I do this through a contentScript with pageMod.

var pageMod = require("sdk/page-mod");
pageMod.PageMod({
  include: "https://hack.chat/?*",
  contentScriptFile: self.data.url("contentScript.js")
});

The site itself has a client.js script. However my contentScript is not able to read vaiables from said script, nor call functions.

For example, the server calls ‘pushMessage(args)’, the script should catch the function call, work some data, then send the message to client.js

See unsafeWindow: https://developer.mozilla.org/en-US/Add-ons/SDK/Guides/Content_Scripts/Interacting_with_page_scripts#Access_objects_defined_by_page_scripts

Also read about wrappedJSObject: https://developer.mozilla.org/en/docs/wrappedJSObject

Except none of those are encouraged to use.

As it turns out using SubScriptLoader on content window global (from frame/content script) effectively creates page scripts which is exactly what you want when overriding website JS.

https://developer.mozilla.org/en-US/Add-ons/Overlay_Extensions/XUL_School/Appendix_D:_Loading_Scripts#The_Sub-Script_Loader

Just the other day I used Cu.Sandbox and it was awesome: