From 0eaa8ee767a742641a33b59ba5e62c1a43c8b357 Mon Sep 17 00:00:00 2001 From: Philip Reimer Date: Tue, 3 Nov 2020 19:34:25 +0100 Subject: [PATCH 1/4] fixes #1081 If input field does not have focus: - show autocomplete list if there are multiple credentials - otherwise fill in credentials --- .../content/keepassxc-browser.js | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/keepassxc-browser/content/keepassxc-browser.js b/keepassxc-browser/content/keepassxc-browser.js index ee38c4f..2c336d3 100755 --- a/keepassxc-browser/content/keepassxc-browser.js +++ b/keepassxc-browser/content/keepassxc-browser.js @@ -727,19 +727,22 @@ kpxc.fillInFromActiveElement = async function(passOnly = false) { } const el = document.activeElement; - if (el.nodeName !== 'INPUT') { - // No active input element selected -> fill the first combination found - if (kpxc.combinations.length > 0) { - kpxc.fillInCredentials(kpxc.combinations[0], kpxc.credentials[0].login, kpxc.credentials[0].uuid, passOnly); - - // Focus to the input field - const field = passOnly ? kpxc.combinations[0].password : kpxc.combinations[0].username; - if (field) { - field.focus(); - } + if (el.nodeName !== 'INPUT' && kpxc.combinations.length > 0 && kpxc.settings.autoCompleteUsernames) { + // No active input element selected -> focus to the input field + const field = passOnly ? kpxc.combinations[0].password : kpxc.combinations[0].username; + if (field) { + field.focus(); } - return; + if (kpxc.credentials.length > 1) { + // More than one credential -> show autocomplete list + kpxcAutocomplete.showList(field); + return + } else { + // Just one credential -> fill the first combination found + kpxc.fillInCredentials(kpxc.combinations[0], kpxc.credentials[0].login, kpxc.credentials[0].uuid, passOnly); + return; + } } else if (kpxc.credentials.length > 1 && kpxc.combinations.length > 0 && kpxc.settings.autoCompleteUsernames) { kpxcAutocomplete.showList(el); return; From efb6b031f5b2d53830e152fc883c209291b13019 Mon Sep 17 00:00:00 2001 From: Philip Reimer Date: Thu, 5 Nov 2020 23:37:41 +0100 Subject: [PATCH 2/4] only focus if field can be determined from combinations and if the field is not the current active element --- .../content/keepassxc-browser.js | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/keepassxc-browser/content/keepassxc-browser.js b/keepassxc-browser/content/keepassxc-browser.js index 2c336d3..24f5fd1 100755 --- a/keepassxc-browser/content/keepassxc-browser.js +++ b/keepassxc-browser/content/keepassxc-browser.js @@ -727,25 +727,26 @@ kpxc.fillInFromActiveElement = async function(passOnly = false) { } const el = document.activeElement; - if (el.nodeName !== 'INPUT' && kpxc.combinations.length > 0 && kpxc.settings.autoCompleteUsernames) { - // No active input element selected -> focus to the input field - const field = passOnly ? kpxc.combinations[0].password : kpxc.combinations[0].username; - if (field) { - field.focus(); - } - if (kpxc.credentials.length > 1) { - // More than one credential -> show autocomplete list - kpxcAutocomplete.showList(field); - return - } else { - // Just one credential -> fill the first combination found - kpxc.fillInCredentials(kpxc.combinations[0], kpxc.credentials[0].login, kpxc.credentials[0].uuid, passOnly); + if (kpxc.combinations.length > 0 && kpxc.settings.autoCompleteUsernames) { + const field = passOnly ? kpxc.combinations[0].password : kpxc.combinations[0].username; + if (field && field.id !== el.id) { + // focus to the correct input field + field.focus(); + + if (kpxc.credentials.length > 1) { + // More than one credential -> show autocomplete list + kpxcAutocomplete.showList(field); + return + } else { + // Just one credential -> fill the first combination found + kpxc.fillInCredentials(kpxc.combinations[0], kpxc.credentials[0].login, kpxc.credentials[0].uuid, passOnly); + return; + } + } else if (kpxc.credentials.length > 1) { + kpxcAutocomplete.showList(el); return; } - } else if (kpxc.credentials.length > 1 && kpxc.combinations.length > 0 && kpxc.settings.autoCompleteUsernames) { - kpxcAutocomplete.showList(el); - return; } // No previous combinations detected. Create a new one from active element From c82c5dd0b6e26ce7f0e3f1043793d2b6b1b01dd5 Mon Sep 17 00:00:00 2001 From: Philip Reimer Date: Wed, 11 Nov 2020 00:39:58 +0100 Subject: [PATCH 3/4] set focus to username or password input field regardless of the currently active element if at least one combination exists and autocomplete is enabled --- .../content/keepassxc-browser.js | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/keepassxc-browser/content/keepassxc-browser.js b/keepassxc-browser/content/keepassxc-browser.js index 24f5fd1..0cee121 100755 --- a/keepassxc-browser/content/keepassxc-browser.js +++ b/keepassxc-browser/content/keepassxc-browser.js @@ -726,30 +726,24 @@ kpxc.fillInFromActiveElement = async function(passOnly = false) { return; } - const el = document.activeElement; - if (kpxc.combinations.length > 0 && kpxc.settings.autoCompleteUsernames) { const field = passOnly ? kpxc.combinations[0].password : kpxc.combinations[0].username; - if (field && field.id !== el.id) { - // focus to the correct input field - field.focus(); + // set focus to the input field + field.focus(); - if (kpxc.credentials.length > 1) { - // More than one credential -> show autocomplete list - kpxcAutocomplete.showList(field); - return - } else { - // Just one credential -> fill the first combination found - kpxc.fillInCredentials(kpxc.combinations[0], kpxc.credentials[0].login, kpxc.credentials[0].uuid, passOnly); - return; - } - } else if (kpxc.credentials.length > 1) { - kpxcAutocomplete.showList(el); + if (kpxc.credentials.length > 1) { + // More than one credential -> show autocomplete list + kpxcAutocomplete.showList(field); + return + } else { + // Just one credential -> fill the first combination found + kpxc.fillInCredentials(kpxc.combinations[0], kpxc.credentials[0].login, kpxc.credentials[0].uuid, passOnly); return; } } // No previous combinations detected. Create a new one from active element + const el = document.activeElement; let combination; if (kpxc.combinations.length === 0) { combination = await kpxc.createCombination(el); From b24efdcf217f6a05b0676dd5bc888cf99312fc06 Mon Sep 17 00:00:00 2001 From: Philip Reimer Date: Fri, 13 Nov 2020 00:44:47 +0100 Subject: [PATCH 4/4] find the correct combination and field for two-step login flows, like Google and Paypal --- keepassxc-browser/content/keepassxc-browser.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/keepassxc-browser/content/keepassxc-browser.js b/keepassxc-browser/content/keepassxc-browser.js index 0cee121..d3aaad8 100755 --- a/keepassxc-browser/content/keepassxc-browser.js +++ b/keepassxc-browser/content/keepassxc-browser.js @@ -727,7 +727,18 @@ kpxc.fillInFromActiveElement = async function(passOnly = false) { } if (kpxc.combinations.length > 0 && kpxc.settings.autoCompleteUsernames) { - const field = passOnly ? kpxc.combinations[0].password : kpxc.combinations[0].username; + const combination = passOnly + ? kpxc.combinations.find(c => c.password) + : kpxc.combinations.find(c => c.username); + if (!combination) { + return; + } + + const field = passOnly ? combination.password : combination.username; + if (!field) { + return; + } + // set focus to the input field field.focus(); @@ -737,7 +748,7 @@ kpxc.fillInFromActiveElement = async function(passOnly = false) { return } else { // Just one credential -> fill the first combination found - kpxc.fillInCredentials(kpxc.combinations[0], kpxc.credentials[0].login, kpxc.credentials[0].uuid, passOnly); + kpxc.fillInCredentials(combination, kpxc.credentials[0].login, kpxc.credentials[0].uuid, passOnly); return; } }