I am trying to write an add-on for Firefox Electrolysis. When I open an e10s window and right click on a page element, document.popupNode is not available for e10s window.
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);
You can use test code in Scratchpad. After running test code, open a new normal Firefox window and right click inside a web page. Prompt alert appears for the document.popupNode.
But if a new e10s Firefox window is opened and right clicked, it does not show anything.
How can I get the document.popupNode in e10s windows?
There is no document.popupNode
because the XUL document didn't pop anything up at a node. Instead it received a message from the child process that told it to display the menu at certain screen coordinates.
Instead, use gContextMenu.target
, which is populated from gContextMenuContentData.event.target
.
gContextMenu.target
is available all browser windows, while gContextMenuContentData.event.target
is only available in e10s windows.
Of course, gContextMenu
is only valid when a popup is about to show or showing.