From 6fcd817e9624479c542cff5aab2389af820f6e42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20V=C3=A4nttinen?= Date: Tue, 23 Sep 2025 15:45:58 +0300 Subject: [PATCH] Fix filling wrapped input fields (#2699) Fix filling Reddit 2FA field --- keepassxc-browser/content/form.js | 6 +++--- keepassxc-browser/content/keepassxc-browser.js | 10 +++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/keepassxc-browser/content/form.js b/keepassxc-browser/content/form.js index 86a156e..d916be0 100644 --- a/keepassxc-browser/content/form.js +++ b/keepassxc-browser/content/form.js @@ -116,9 +116,9 @@ kpxcForm.getNewPassword = function(passwordInputs = []) { } // Choose the last three password fields. The first ones are almost always for something else - const current = passwordInputs[passwordInputs.length - 3].value; - const newPass = passwordInputs[passwordInputs.length - 2].value; - const repeatNew = passwordInputs[passwordInputs.length - 1].value; + const current = passwordInputs[passwordInputs.length - 3]?.value; + const newPass = passwordInputs[passwordInputs.length - 2]?.value; + const repeatNew = passwordInputs[passwordInputs.length - 1]?.value; if ((newPass === repeatNew && current !== newPass && current !== repeatNew) || (current === newPass && repeatNew !== newPass && repeatNew !== current)) { diff --git a/keepassxc-browser/content/keepassxc-browser.js b/keepassxc-browser/content/keepassxc-browser.js index 2351990..2c94c70 100755 --- a/keepassxc-browser/content/keepassxc-browser.js +++ b/keepassxc-browser/content/keepassxc-browser.js @@ -736,12 +736,20 @@ kpxc.setValue = function(field, value, forced = false) { field.checked = true; } + // Make sure the input is not wrapped inside another element (custom INPUT element) + if (field?.nodeName !== 'INPUT' && field?.nodeName?.includes('INPUT')) { + const childInput = field?.querySelector('input'); + const fieldsFromShadowDOM = kpxcObserverHelper.findInputsFromShadowDOM(field); + field = childInput ?? fieldsFromShadowDOM[0]; + } + + kpxc.setValueWithChange(field, value, forced); }; // Sets a new value to input field and triggers necessary events kpxc.setValueWithChange = function(field, value, forced = false) { - if (!forced && field.readOnly) { + if (!field || (field?.readOnly && !forced)) { return; }