电解兼容垫片不适用于evalInSandbox [英] Electrolysis compatibility shims doesn't work with evalInSandbox
问题描述
我们可以访问内容(例如使用window.content)我们的一些脚本(例如覆盖脚本)。但是,我们的扩展也使用evalInSandbox加载一些脚本。它看起来像这样:
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);
我们似乎无法访问在沙盒中加载的脚本的window.content。在这种情况下垫片似乎不起作用。这是一个错误,或者是由设计?
谢谢
<您的sandboxPrototype是错误的,您将它设置为 nsIDOMWindow
,将其设置为 aNSIDOMWindow.gBrowser.tabContainer.childNodes [tab_index_goes_here] .contentWindow
在mdn上看到这个例子: https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.Sandbox 这里是如何加载脚本作为文件,而不是做evalInSandbox: https://github.com/Noitidart/modtools 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: 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 Your sandboxPrototype is wrong, you are setting it to the 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 这篇关于电解兼容垫片不适用于evalInSandbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
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);
nsIDOMWindow
, set it to the aNSIDOMWindow.gBrowser.tabContainer.childNodes[tab_index_goes_here].contentWindow