电解兼容垫片不适用于evalInSandbox [英] Electrolysis compatibility shims doesn't work with evalInSandbox

查看:142
本文介绍了电解兼容垫片不适用于evalInSandbox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个相当古老的XUL扩展,我们希望确保与Electrolysis合作。我们最终将把它迁移到WebExtensions API,但现在我们要使用兼容填充。



我们可以访问内容(例如使用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:

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

解决方案

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

这篇关于电解兼容垫片不适用于evalInSandbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆