From ed6064912e0740a775a4fa9ab765565f1f8afde7 Mon Sep 17 00:00:00 2001 From: AlexVallat Date: Sat, 25 Apr 2015 18:33:20 +0100 Subject: [PATCH] Fix for race condition adding double context menu entries --- platform/firefox/vapi-background.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index f54d00e64..5e16467b2 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -1969,11 +1969,18 @@ vAPI.contextMenu.register = function(doc) { return; } + if (doc.getElementById(this.menuItemId)) { + // Context menu already registered for this window + return; + } + var contextMenu = doc.getElementById('contentAreaContextMenu'); - var menuitem = this.createContextMenuItem(doc); - menuitem.addEventListener('command', this.onCommand); - contextMenu.addEventListener('popupshowing', this.displayMenuItem); - contextMenu.insertBefore(menuitem, doc.getElementById('inspect-separator')); + if (contextMenu) { + var menuitem = this.createContextMenuItem(doc); + menuitem.addEventListener('command', this.onCommand); + contextMenu.addEventListener('popupshowing', this.displayMenuItem); + contextMenu.insertBefore(menuitem, doc.getElementById('inspect-separator')); + } }; /******************************************************************************/