Firefox 中的 iFrame 隐藏窗口带有 contentWindow.history?
我正在尝试在我的 Firefox 扩展中运行具有内容权限的托管脚本。为此,我在隐藏窗口中创建一个内容 iframe,指向提取脚本的 html 文件。该脚本要求“历史记录”可用,但由于某种原因,在隐藏窗口中创建的 iframe 没有历史记录。
Chromebug 针对 iframe 的 contentWindow.history 报告此情况:
对象不支持历史记录 (nsIDOMHistory)
并且脚本在其不可用时给出此错误:
错误:组件返回失败代码:0x80004005 (NS_ERROR_FAILURE) [nsIDOMHistory.length]
有什么想法吗?
I'm trying to run a hosted script with content privileges in my Firefox extension. To do this, I create a content iframe in the hidden window pointed at a html file that pulls the script. This script requires the 'history' be available, but the iframes created in the hidden window have no history for some reason.
Chromebug reports this for the iframe's contentWindow.history:
object does not support history (nsIDOMHistory)
And the script gives this error when its not available:
Error: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMHistory.length]
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实证明,隐藏窗口的 URL 曾经是 about:blank,但这显然是一个安全缺陷,所以现在是 resources://gre/res/hiddenWindow.html (或 resource://gre-resources/hiddenWindow.html)。 html on trunk),因此它不具有 XUL 浏览器元素所需的 chrome 权限,以便能够连接其自己的会话历史记录,甚至访问其自己的内容文档。
即使使用 XUL iframe 元素,您也必须小心,因为它的所有属性都不起作用,同样是因为它在没有 chrome 权限的情况下运行。因此,您必须执行 iframeElement.boxObject.QueryInterface(Components.interfaces.nsIContainerBoxObject).docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindow) 之类的操作来检索其内容窗口。
It turns out that the hidden window's URL used to be about:blank, but this was apparently a security flaw, so it is now resource://gre/res/hiddenWindow.html (or resource://gre-resources/hiddenWindow.html on trunk) so it doesn't have the chrome privileges that a XUL browser element needs in order to be able to wire up its own session history, or even to access its own content document.
Even using a XUL iframe element you have to be careful since none of its properties work, again because it is running without chrome privileges. So you have to do stuff like iframeElement.boxObject.QueryInterface(Components.interfaces.nsIContainerBoxObject).docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindow) to retrieve its content window.
<浏览器类型=“内容”>默认情况下会自动连接会话历史记录,而
不要忘记确保您的元素是在 XUL 命名空间中创建的。我相信隐藏的窗口是 about:blank HTML 文档(Mac 上除外)。
A <browser type="content"> will automatically wire up session history by default, while an <iframe type="content"> will not, but you could always wire it up yourself manually.
Don't forget to ensure that your element is created in the XUL namespace. I believe the hidden window is the about:blank HTML document except on the Mac.