With FF 36.0.4, I got these errors (below) in the log windows when I right click to open the context menu.
Strangely this does not happen on my default profile, but on my dev profile where I have no extension installed but the one I'm testing
SyntaxError: function statement requires a name browser.xul:1:9
TypeError: gContextMenu is null browser.xul:1:96
and the javascript function attached to the menu are not run
....
Well digging a little, I have found that I was using
tempItem.setAttribute("oncommand", cmd);
instead of
tempItem.addEventListener("command", cmd, false);
and that was the origin of the error function statement requires a name (I just see that this error disapear... I don't understand what's hapening)
I still have gContextMenu is null but my js call is executed
François
gContextMenu is null
-
- Posts: 3664
- Joined: September 15th, 2010, 9:03 am
Re: gContextMenu is null
Strangely it only happens with the addon you're testing? Odd that
Is cmd a string? Should work, although a bad idea. Or a function? Setting an attribute to a function, not too clever, probably won't do what you hoped for. Funcrions work well with addEventListener(), not so well with setAttribute().
gContextMenu is set to a new object when the content area context menu is opened, then destroyed when it is closed. You may be blocking the event handler that creates gContextMenu, or perhaps overwriting it by setting the onpopupshowing attribute to something else. Never set handler attributes on elements unless you created them because you stomp all over whatever is already there. Even if you don't think anything is already there, some other addon may have the same idea. Or popuphiding events are bubbling up from a submenu and destroying gContextMenu?
Is cmd a string? Should work, although a bad idea. Or a function? Setting an attribute to a function, not too clever, probably won't do what you hoped for. Funcrions work well with addEventListener(), not so well with setAttribute().
gContextMenu is set to a new object when the content area context menu is opened, then destroyed when it is closed. You may be blocking the event handler that creates gContextMenu, or perhaps overwriting it by setting the onpopupshowing attribute to something else. Never set handler attributes on elements unless you created them because you stomp all over whatever is already there. Even if you don't think anything is already there, some other addon may have the same idea. Or popuphiding events are bubbling up from a submenu and destroying gContextMenu?
-
- Posts: 57
- Joined: January 15th, 2010, 8:57 am
Re: gContextMenu is null
Thanks for replying, yes my fault.
cmd is a anonymous function and is pass as a parameter with
function(event){filteredClipboard.paste(event);}
Now if I try to explain what my code is doing, I would say:
my binding xml file have these bindings
filteredClipboard_scroll (id) with the content
filteredClipboard-scroll-text (id) that extends the above, and that bind two js calls to the same function on popupshowing, one for displaying a past menu, the other for a copy menu.
The js function populate the menu items and add the event listener to react to a menu selection.
filteredClipboard_hide (id) that extends popup.xml#popup and that bind js calls (to the same function) on popupshowing,
to hide or not the past or copy menu depending on
- where the mouse pointer is,
- if some text is selected,
- if the past command is activated ....
So, I would say I'm attaching js function on xul element I'm creating, am I not ?
Or is it with the hiding that's bubbling up ?
Cheers
François
cmd is a anonymous function and is pass as a parameter with
function(event){filteredClipboard.paste(event);}
Now if I try to explain what my code is doing, I would say:
my binding xml file have these bindings
filteredClipboard_scroll (id) with the content
Code: Select all
<children/>
<xul:menuseparator anonid="sep-filteredClipboard-copy" />
<xul:menu anonid="context-filteredClipboard-copy" label="&filteredClipboard.copymenu;" accesskey="&filteredClipboard.copykey;">
<xul:menupopup anonid="filteredClipboard-popup-copy" style="-moz-binding:none">
</xul:menupopup>
</xul:menu>
<xul:menuseparator anonid="sep-filteredClipboard-paste" />
<xul:menu anonid="context-filteredClipboard-paste" label="&filteredClipboard.pastemenu;" accesskey="&filteredClipboard.pastekey;">
<xul:menupopup anonid="filteredClipboard-popup-paste" style="-moz-binding:none">
</xul:menupopup>
</xul:menu>
filteredClipboard-scroll-text (id) that extends the above, and that bind two js calls to the same function on popupshowing, one for displaying a past menu, the other for a copy menu.
The js function populate the menu items and add the event listener to react to a menu selection.
filteredClipboard_hide (id) that extends popup.xml#popup and that bind js calls (to the same function) on popupshowing,
to hide or not the past or copy menu depending on
- where the mouse pointer is,
- if some text is selected,
- if the past command is activated ....
So, I would say I'm attaching js function on xul element I'm creating, am I not ?
Or is it with the hiding that's bubbling up ?
Cheers
François
-
- Posts: 3664
- Joined: September 15th, 2010, 9:03 am
Re: gContextMenu is null
The popuphiding event *is* bubbling up. However, standard practice with this type of event is to check that it actually applies to the observed element before acting and browser.xul does this so it shouldn't be affected by your own menu hiding.
Still, the error is being generated by the onpopupshowing handler for the content area context menu. The likely cause is that the handler is being called twice, assuming that nobody else is overwriting or destroying that object. Perhaps the handler is called but then the closing is blocked? Does your code do anything like that?
Still, the error is being generated by the onpopupshowing handler for the content area context menu. The likely cause is that the handler is being called twice, assuming that nobody else is overwriting or destroying that object. Perhaps the handler is called but then the closing is blocked? Does your code do anything like that?
-
- Posts: 57
- Joined: January 15th, 2010, 8:57 am
Re: gContextMenu is null
Oh yes, twice could be the clue:
I have two versions of my extension, one that does not gives the error, and that have one xml binding file,
This is unfortunatly what I had described in my message above....
The version that does give the gcontextMenu is null error has two binding files: fcb_past.xml, fcb_copy.xml:
fcb_past.xml for example has the binding fcb_scroll_text that extends the binding with the same name in fcb_copy file
the handler for popupshowing is
fcb_copy.xml has the binding fcb_scroll_text that extends fcb_scroll as defined in my previous post. The handler on popupshowing is almost the same as the one above except for the string in the last param.
The css file bind the dom elements with the binding in the fcb_paste.xml file, for example:
Is this inheritance in these two binding files that cause the handler being called twice ?
In my one-file error-free version the binding has two js call to prepareContextMenu
Basicaly it's called twice also here, no?
François
I have two versions of my extension, one that does not gives the error, and that have one xml binding file,
This is unfortunatly what I had described in my message above....
The version that does give the gcontextMenu is null error has two binding files: fcb_past.xml, fcb_copy.xml:
fcb_past.xml for example has the binding fcb_scroll_text that extends the binding with the same name in fcb_copy file
the handler for popupshowing is
Code: Select all
var elem =document.getAnonymousNodes(this);
var last = elem.length-1;
prepareContextMenu(elem[last], 1, "filteredClipboard-popup-paste");
fcb_copy.xml has the binding fcb_scroll_text that extends fcb_scroll as defined in my previous post. The handler on popupshowing is almost the same as the one above except for the string in the last param.
The css file bind the dom elements with the binding in the fcb_paste.xml file, for example:
Code: Select all
menupopup#contentAreaContextMenu > arrowscrollbox.popup-internal-box > scrollbox {-moz-binding: url("chrome://filteredclipboard/content/fcb_paste.xml#filteredClipboard-scroll-text");}
Is this inheritance in these two binding files that cause the handler being called twice ?
In my one-file error-free version the binding has two js call to prepareContextMenu
Code: Select all
var elem =document.getAnonymousNodes(this);
var last = elem.length-1;
prepareContextMenu(elem[last], 0, "filteredClipboard-popup-paste");
prepareContextMenu(elem[last-2], 0, "filteredClipboard-popup-copy");
Basicaly it's called twice also here, no?
François
-
- Posts: 3664
- Joined: September 15th, 2010, 9:03 am
Re: gContextMenu is null
You're flailing. I'm guessing. Debug it properly. For example, replace what we know is the offending popuphiding attribute with your own so you can tell exactly when it is being called and extract any information that could be useful. You can include the original code if that is necessary to stop everything going haywire. Obviously you can also debug when your own handlers are getting called, to make sure it is what you expect.
-
- Posts: 57
- Joined: January 15th, 2010, 8:57 am
Re: gContextMenu is null
The code is here
http://homeweb3.unifr.ch/rappazf/Pub/fcb/filteredclipboard1.4.9_2bindings_version.zip
I can't remove the error message with commenting out part of the code.
The error message appears when all the js code has run, and the popup closes.
And on further testing I see that my one binding version also produces this error...
http://homeweb3.unifr.ch/rappazf/Pub/fcb/filteredclipboard1.4.9_2bindings_version.zip
I can't remove the error message with commenting out part of the code.
The error message appears when all the js code has run, and the popup closes.
And on further testing I see that my one binding version also produces this error...
-
- Posts: 2810
- Joined: November 15th, 2004, 5:03 am
Re: gContextMenu is null
window.gContextMenu where the window loads the document browser.xul
gContextMenu should have value while content area context menu is showing and at the start of a command function from a menu item. If you delay getting it (something asynchronous?) it can be cleared/null. Might check it and set a variable at the start of function, or perhaps set one 1ms after popupshowing, while content area context menu is showing.
gContextMenu should have value while content area context menu is showing and at the start of a command function from a menu item. If you delay getting it (something asynchronous?) it can be cleared/null. Might check it and set a variable at the start of function, or perhaps set one 1ms after popupshowing, while content area context menu is showing.