如何在 contentaccessible=yes 失败时注入脚本
How to inject script when contentaccessible=yes fails
我必须在网页中收听 jquery 事件。我无法从 wrappedJSObject 附加函数,因为它在执行 chrome 范围内创建的函数时遇到问题。
所以我想动态插入一个脚本,它会发送一个自定义事件,我的插件会监听该事件。但这是一个简单的例子,只需插入警报脚本:
var aContentWindow = gBrowser.contentWindow;
var aContentDocument = aContentWindow.document;
var myScript = aContentDocument.createElement('script');
myScript.textContent = 'alert("registered");'
aContentDocument.documentElement.appendChild(myScript);
所以我正在尝试 运行 这个网站是推特,它在其他网站上有效。
所以我认为让我们从具有 contentaccessible=true
的 chrome 路径的插件范围执行此操作,所以我这样做了,但它仍然会给我错误:
Content Security Policy: The page's settings blocked the loading of a resource at self ("script-src 'unsafe-inline' 'nonce-hnhqgKrLIxRgkHGdVqfgfA==' 'unsafe-eval' https://twitter.com https://*.twimg.com https://twitter.com https://ton.twitter.com https://platform.twitter.com https://syndication.twitter.com https://analytics.twitter.com https://www.google-analytics.com https://ssl.google-analytics.com https://connect.facebook.net https://cm.g.doubleclick.net https://api.twitter.com https://graph.facebook.com https://www.google.com"). twitter.com:562:0
同时还有第二个:
Content Security Policy: The page's settings blocked the loading of a resource at self ("script-src 'unsafe-inline' 'nonce-hnhqgKrLIxRgkHGdVqfgfA==' 'unsafe-eval' https://twitter.com https://*.twimg.com https://twitter.com https://ton.twitter.com https://platform.twitter.com https://syndication.twitter.com https://analytics.twitter.com https://www.google-analytics.com https://ssl.google-analytics.com https://connect.facebook.net https://cm.g.doubleclick.net https://api.twitter.com https://graph.facebook.com https://www.google.com").
知道如何将此脚本放入其中吗?
您是否尝试过 subscript loader,将 wrappedJSObject 作为目标上下文,而不是操纵 DOM?
您可以尝试的另一件事是创建 a sandbox,将目标 window 指定为 sandboxPrototype
,将 wantXrays
设置为 false
并使用目标 window 的 document.domain
作为安全主体。
这应该会为您提供一个可以完全访问目标 window 的沙箱,不会引发任何安全错误,因为它将使用 transparent wrappers.
一旦你有了那个沙箱,你就可以通过 evalInSandbox 在沙箱中尝试 运行 你的脚本,或者使用下标加载器将沙箱作为目标而不是 window。
我必须在网页中收听 jquery 事件。我无法从 wrappedJSObject 附加函数,因为它在执行 chrome 范围内创建的函数时遇到问题。
所以我想动态插入一个脚本,它会发送一个自定义事件,我的插件会监听该事件。但这是一个简单的例子,只需插入警报脚本:
var aContentWindow = gBrowser.contentWindow;
var aContentDocument = aContentWindow.document;
var myScript = aContentDocument.createElement('script');
myScript.textContent = 'alert("registered");'
aContentDocument.documentElement.appendChild(myScript);
所以我正在尝试 运行 这个网站是推特,它在其他网站上有效。
所以我认为让我们从具有 contentaccessible=true
的 chrome 路径的插件范围执行此操作,所以我这样做了,但它仍然会给我错误:
Content Security Policy: The page's settings blocked the loading of a resource at self ("script-src 'unsafe-inline' 'nonce-hnhqgKrLIxRgkHGdVqfgfA==' 'unsafe-eval' https://twitter.com https://*.twimg.com https://twitter.com https://ton.twitter.com https://platform.twitter.com https://syndication.twitter.com https://analytics.twitter.com https://www.google-analytics.com https://ssl.google-analytics.com https://connect.facebook.net https://cm.g.doubleclick.net https://api.twitter.com https://graph.facebook.com https://www.google.com"). twitter.com:562:0
同时还有第二个:
Content Security Policy: The page's settings blocked the loading of a resource at self ("script-src 'unsafe-inline' 'nonce-hnhqgKrLIxRgkHGdVqfgfA==' 'unsafe-eval' https://twitter.com https://*.twimg.com https://twitter.com https://ton.twitter.com https://platform.twitter.com https://syndication.twitter.com https://analytics.twitter.com https://www.google-analytics.com https://ssl.google-analytics.com https://connect.facebook.net https://cm.g.doubleclick.net https://api.twitter.com https://graph.facebook.com https://www.google.com").
知道如何将此脚本放入其中吗?
您是否尝试过 subscript loader,将 wrappedJSObject 作为目标上下文,而不是操纵 DOM?
您可以尝试的另一件事是创建 a sandbox,将目标 window 指定为 sandboxPrototype
,将 wantXrays
设置为 false
并使用目标 window 的 document.domain
作为安全主体。
这应该会为您提供一个可以完全访问目标 window 的沙箱,不会引发任何安全错误,因为它将使用 transparent wrappers.
一旦你有了那个沙箱,你就可以通过 evalInSandbox 在沙箱中尝试 运行 你的脚本,或者使用下标加载器将沙箱作为目标而不是 window。