diff --git a/keepassxc-browser/_locales/en/messages.json b/keepassxc-browser/_locales/en/messages.json index a05f447..15f1ffc 100644 --- a/keepassxc-browser/_locales/en/messages.json +++ b/keepassxc-browser/_locales/en/messages.json @@ -779,6 +779,14 @@ "message": "An HTTP Basic Auth dialog looks like this:", "description": "HTTP Basic Auth image help text." }, + "optionsClearCredentialsTimeout": { + "message": "Clear credentials from non-active tabs after (seconds, 0-3600).", + "description": "Clear credentials label text." + }, + "optionsClearCredentialsTimeoutHelpText": { + "message": "Credentials are cleared from background tabs after the timeout and permissions for those pages will be asked again.", + "description": "Clear credentials timeout help text." + }, "optionsVersionInfoText": { "message": "KeePassXC-Browser needs KeePassXC to retrieve credentials.", "description": "Settings page version info text." diff --git a/keepassxc-browser/background/page.js b/keepassxc-browser/background/page.js index 96338c9..126b8b4 100755 --- a/keepassxc-browser/background/page.js +++ b/keepassxc-browser/background/page.js @@ -9,6 +9,7 @@ const defaultSettings = { autoRetrieveCredentials: true, autoSubmit: false, checkUpdateKeePassXC: 3, + clearCredentialsTimeout: 10, colorTheme: 'system', credentialSorting: SORT_BY_GROUP_AND_TITLE, defaultGroup: '', @@ -27,6 +28,7 @@ const defaultSettings = { var page = {}; page.attributeMenuItemIds = []; page.blockedTabs = []; +page.clearCredentialsTimeout = null; page.currentRequest = {}; page.currentTabId = -1; page.loginId = -1; @@ -83,6 +85,10 @@ page.initSettings = async function() { page.settings.colorTheme = defaultSettings.colorTheme; } + if (!('clearCredentialsTimeout' in page.settings)) { + page.settings.clearCredentialsTimeout = defaultSettings.clearCredentialsTimeout; + } + if (!('credentialSorting' in page.settings)) { page.settings.credentialSorting = defaultSettings.credentialSorting; } @@ -177,12 +183,18 @@ page.initSitePreferences = async function() { }; page.switchTab = async function(tab) { + // Clears Fill Attribute selection from context menu browser.contextMenus.update('fill_attribute', { visible: false }); - if (page.tabs[tab.id] - && page.tabs[tab.id].credentials.length > 0 - && page.tabs[tab.id].credentials.some(e => e.stringFields && e.stringFields.length > 0)) { - await page.updateContextMenu(tab, page.tabs[tab.id].credentials); - } + + // Clears all logins from other tabs after a timeout + clearTimeout(page.clearCredentialsTimeout); + page.clearCredentialsTimeout = setTimeout(() => { + for (const pageTabId of Object.keys(page.tabs)) { + if (tab.id !== Number(pageTabId)) { + page.clearCredentials(Number(pageTabId), true); + } + } + }, page.settings.clearCredentialsTimeout * 1000); browserAction.showDefault(tab); browser.tabs.sendMessage(tab.id, { action: 'activated_tab' }).catch((e) => { diff --git a/keepassxc-browser/content/keepassxc-browser.js b/keepassxc-browser/content/keepassxc-browser.js index f0eff41..23e2f61 100755 --- a/keepassxc-browser/content/keepassxc-browser.js +++ b/keepassxc-browser/content/keepassxc-browser.js @@ -6,7 +6,6 @@ const _maximumMutations = 200; // Contains already called method names const _called = {}; _called.automaticRedetectCompleted = false; -_called.clearLogins = false; _called.retrieveCredentials = false; // Wrapper @@ -1289,9 +1288,6 @@ kpxc.initCombinations = async function(inputs = []) { // The main function for finding input fields kpxc.initCredentialFields = async function() { - await sendMessage('page_clear_logins', _called.clearLogins); - _called.clearLogins = true; - // Identify all forms in the page const formInputs = await kpxc.identifyFormInputs(); diff --git a/keepassxc-browser/options/options.html b/keepassxc-browser/options/options.html index 37d812e..fa49abf 100644 --- a/keepassxc-browser/options/options.html +++ b/keepassxc-browser/options/options.html @@ -36,7 +36,7 @@