diff --git a/src/background.js b/src/background.js index 55586ee0..7dd24016 100644 --- a/src/background.js +++ b/src/background.js @@ -31,7 +31,8 @@ chrome.commands.onCommand.addListener(function (command) { var loadMenuRan = false, loginToAutoFill = null, pageDetailsToAutoFill = [], - autofillTimeout = null; + autofillTimeout = null, + menuOptionsLoaded = []; chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) { if (msg.command === 'loggedIn' || msg.command === 'unlocked' || msg.command === 'locked') { @@ -156,6 +157,15 @@ function buildContextMenu(callback) { contexts: ['all'], title: i18nService.autoFill }, function () { + if (utilsService.isFirefox()) { + // Firefox does not support writing to the clipboard from background + buildingContextMenu = false; + if (callback) { + callback(); + } + return; + } + chrome.contextMenus.create({ type: 'normal', id: 'copy-username', @@ -220,7 +230,7 @@ chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) { }); chrome.windows.onFocusChanged.addListener(function (windowId) { - if (!windowId || windowId < 0) { + if (windowId === null || windowId < 0) { return; } @@ -257,10 +267,12 @@ function loadMenuAndUpdateBadge(url, tabId, loadContextMenuOptions) { chrome.browserAction.setBadgeBackgroundColor({ color: '#294e5f' }); + menuOptionsLoaded = []; loginService.getAllDecryptedForDomain(tabDomain).then(function (logins) { sortLogins(logins); - for (var i = 0; i < logins.length; i++) { - if (loadContextMenuOptions) { + + if (loadContextMenuOptions) { + for (var i = 0; i < logins.length; i++) { loadLoginContextMenuOptions(logins[i]); } } @@ -578,12 +590,11 @@ function loadNoLoginsContextMenuOptions(noLoginsMessage) { loadContextMenuOptions(noLoginsMessage, 'noop', null); } -var loadingContextMenuOptions = false; function loadContextMenuOptions(title, idSuffix, login) { - if (loadingContextMenuOptions) { + if (menuOptionsLoaded.indexOf(idSuffix) > -1) { return; } - loadingContextMenuOptions = true; + menuOptionsLoaded.push(idSuffix); if (!login || (login.password && login.password !== '')) { chrome.contextMenus.create({ @@ -595,6 +606,11 @@ function loadContextMenuOptions(title, idSuffix, login) { }); } + if (utilsService.isFirefox()) { + // Firefox does not support writing to the clipboard from background + return; + } + if (!login || (login.username && login.username !== '')) { chrome.contextMenus.create({ type: 'normal', @@ -614,8 +630,6 @@ function loadContextMenuOptions(title, idSuffix, login) { title: title }); } - - loadingContextMenuOptions = false; } // TODO: Fix callback hell by moving to promises diff --git a/src/manifest.json b/src/manifest.json index 5029eeb2..4e1cc8b0 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -70,6 +70,7 @@ "contextMenus", "storage", "unlimitedStorage", + "clipboardWrite", "http://*/*", "https://*/*" ],