diff --git a/keepassxc-browser/common/sites.js b/keepassxc-browser/common/sites.js index 404a437..c202601 100644 --- a/keepassxc-browser/common/sites.js +++ b/keepassxc-browser/common/sites.js @@ -61,10 +61,12 @@ const PREDEFINED_SITELIST = [ 'https://secure.fnac.com/identity/server/gateway/*' ]; +const awsUrl = 'signin.aws.amazon.com'; +const ebayUrl = 'https://www.ebay.'; +const googleUrl = 'https://accounts.google.com'; + const kpxcSites = {}; -kpxcSites.ebayUrl = 'https://www.ebay.'; kpxcSites.googlePasswordFormUrl = 'https://accounts.google.com/signin/v2/challenge/password'; -kpxcSites.googleUrl = 'https://accounts.google.com'; kpxcSites.savedForm = undefined; /** @@ -127,3 +129,36 @@ kpxcSites.expectedTOTPMaxLength = function() { return MAX_TOTP_INPUT_LENGTH; }; + +/** + * Handles a few exceptions for certain sites where form submit button is not regognized properly. + * @param {object} form Form element + * @returns {object} Button element + */ +kpxcSites.formSubmitButtonExceptionFound = function(form) { + if (form.action.startsWith(googleUrl)) { + const findDiv = $('#identifierNext, #passwordNext'); + if (!findDiv) { + return undefined; + } + + const buttons = findDiv.getElementsByTagName('button'); + kpxcSites.savedForm = form; + return buttons.length > 0 ? buttons[0] : undefined; + } else if (form.action.startsWith(ebayUrl)) { + // For eBay we must return the first button. + for (const i of form.elements) { + if (i.type === 'button') { + return i; + } + } + } else if (form.action.includes(awsUrl)) { + // For Amazon AWS the button is outside the form. + const button = $('#signin_button'); + if (button) { + return button; + } + } + + return undefined; +}; diff --git a/keepassxc-browser/content/keepassxc-browser.js b/keepassxc-browser/content/keepassxc-browser.js index dfafb28..65bf49a 100755 --- a/keepassxc-browser/content/keepassxc-browser.js +++ b/keepassxc-browser/content/keepassxc-browser.js @@ -160,23 +160,10 @@ kpxcForm.getFormSubmitButton = function(form) { const action = kpxc.submitUrl || form.action; - // Special handling for accounts.google.com. The submit button is outside the form. - if (form.action.startsWith(kpxcSites.googleUrl)) { - const findDiv = $('#identifierNext, #passwordNext'); - if (!findDiv) { - return undefined; - } - - const buttons = findDiv.getElementsByTagName('button'); - kpxcSites.savedForm = form; - return buttons.length > 0 ? buttons[0] : undefined; - } else if (form.action.startsWith(kpxcSites.ebayUrl)) { - // For eBay we must return the first button. - for (const i of form.elements) { - if (i.type === 'button') { - return i; - } - } + // Check if the site needs a special handling for retrieving the form submit button + const exceptionButton = kpxcSites.formSubmitButtonExceptionFound(form); + if (exceptionButton) { + return exceptionButton; } if (action.includes(document.location.origin + document.location.pathname)) {