问题
We have a rather old XUL extension which we want to make sure works with Electrolysis. We will eventually migrate it to the WebExtensions API, but for now we want to use the compatibility shims.
We can access content stuff (using window.content for example) in the some of our scripts (e.g, the overlay scripts). However, our extension also load some scripts using evalInSandbox. It look something like this:
var sandbox = Components.utils.Sandbox(Components.classes["@mozilla.org/systemprincipal;1"].createInstance(Components.interfaces.nsIPrincipal), {
sandboxPrototype: window,
wantXrays: false
});
// ...
Components.utils.evalInSandbox(script, sandbox, url, 0);
We don't seem to be able to access window.content on the scripts loaded in the sandbox. It seem like the shims don't work in this case. Is this a bug, or is it by design?
Thanks
回答1:
Your sandboxPrototype is wrong, you are setting it to the nsIDOMWindow
, set it to the aNSIDOMWindow.gBrowser.tabContainer.childNodes[tab_index_goes_here].contentWindow
see this example on mdn: https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.Sandbox#Example
also here is how to load in a script as file rather then doing evalInSandbox:
https://github.com/Noitidart/modtools
来源:https://stackoverflow.com/questions/32483809/electrolysis-compatibility-shims-doesnt-work-with-evalinsandbox