gpt4 book ai didi

javascript - 如何在 Firefox Electrothesis 窗口中获取 document.popupNode

转载 作者:行者123 更新时间:2023-11-28 01:06:58 25 4
gpt4 key购买 nike

我正在尝试为 Firefox Electrothesis 编写一个插件。当我打开 e10s 窗口并右键单击页面元素时,document.popupNode 对于 e10s 窗口不可用。

var WindowListener = {
setupBrowserUI: function(window) {
//
},
tearDownBrowserUI: function(window) {
},
// nsIWindowMediatorListener functions
onOpenWindow: function(xulWindow) {
var domWindow = xulWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindow);
// Wait for it to finish loading
domWindow.addEventListener("load", function listener() {
domWindow.removeEventListener("load", listener, false);
// If this is a browser window then setup its UI
if (domWindow.document.documentElement.getAttribute("windowtype")=="navigator:browser") {

domWindow.document.getElementById('contentAreaContextMenu').addEventListener("popupshowing", function(event){

let document=event.currentTarget.ownerDocument;
let prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
prompts.alert(null, "Test", document.popupNode);

}, false);

}

}, false);
},
onCloseWindow: function(xulWindow) {
},
onWindowTitleChange: function(xulWindow, newTitle) {
}
};

let wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
getService(Components.interfaces.nsIWindowMediator);
// Wait for any new browser windows to open
wm.addListener(WindowListener);

您可以在Scratchpad中使用测试代码。运行测试代码后,打开一个新的普通 Firefox 窗口,然后在网页内右键单击。 document.popupNode 出现提示警报。

但是,如果打开新的 e10s Firefox 窗口并右键单击,它不会显示任何内容。

如何在 e10s windows 中获取 document.popupNode?

最佳答案

没有 document.popupNode 因为 XUL 文档没有在节点上弹出任何内容。相反,它从子进程收到一条消息,告诉它在特定的屏幕坐标处显示菜单。

而是使用 gContextMenu.target,它是从 gContextMenuContentData.event.target 填充的。

gContextMenu.target 适用于所有浏览器窗口,而 gContextMenuContentData.event.target 仅适用于 e10s 窗口。

当然,gContextMenu仅在弹出窗口即将显示或正在显示时才有效。

关于javascript - 如何在 Firefox Electrothesis 窗口中获取 document.popupNode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24954664/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com