Electrolysis compatibility shims doesn't work with evalInSandbox

若如初见. 提交于 2020-01-11 11:36:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!