mirror of
https://github.com/keepassxreboot/keepassxc-browser.git
synced 2026-03-11 08:54:43 +00:00
Show notification when fields are not found
This commit is contained in:
parent
2785f16555
commit
de938259b9
1 changed files with 36 additions and 3 deletions
|
|
@ -437,16 +437,24 @@ kpxcFields.setId = function(target) {
|
|||
|
||||
// Returns generated unique ID's for the element. If XPath ID fails, return the fallback one.
|
||||
kpxcFields.getId = function(idArray, inputField) {
|
||||
if (!idArray || idArray.length < 2) {
|
||||
if (!idArray) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Legacy ID is used. Convert it to the new one if possible
|
||||
if (!Array.isArray(idArray) && idArray.length > 0) {
|
||||
if (idArray === kpxcFields.getLegacyId(inputField)) {
|
||||
idArray = kpxcFields.setId(inputField);
|
||||
}
|
||||
}
|
||||
|
||||
const elementFromXPath = kpxcFields.getElementFromXPathId(idArray[0]);
|
||||
const fallbackId = kpxcFields.getIdFromProperties(inputField);
|
||||
|
||||
return elementFromXPath || (fallbackId === idArray[1] ? inputField : '');
|
||||
};
|
||||
|
||||
// Returns element XPath
|
||||
kpxcFields.getIdFromXPath = function(target) {
|
||||
let xpath = '';
|
||||
let pos;
|
||||
|
|
@ -472,6 +480,7 @@ kpxcFields.getIdFromXPath = function(target) {
|
|||
return xpath;
|
||||
};
|
||||
|
||||
// Generate uniqe ID from properties (new method)
|
||||
kpxcFields.getIdFromProperties = function(target) {
|
||||
if (target.name) {
|
||||
return `${target.nodeName} ${target.type} ${target.name} ${target.placeholder}`;
|
||||
|
|
@ -486,7 +495,20 @@ kpxcFields.getIdFromProperties = function(target) {
|
|||
}
|
||||
|
||||
return `kpxc ${target.type} ${target.clientTop}${target.clientLeft}${target.clientWidth}${target.clientHeight}${target.offsetTop}${target.offsetLeft}`;
|
||||
}
|
||||
};
|
||||
|
||||
// Legacy unique ID generation for converting
|
||||
kpxcFields.getLegacyId = function(target) {
|
||||
if (target.classList.length > 0) {
|
||||
return `${target.nodeName} ${target.type} ${target.classList.value} ${target.name} ${target.placeholder}`;
|
||||
}
|
||||
|
||||
if (target.id && target.id !== '') {
|
||||
return `${target.nodeName} ${target.type} ${kpxcFields.prepareId(target.id)} ${target.name} ${target.placeholder}`;
|
||||
}
|
||||
|
||||
return `kpxc ${target.type} ${target.clientTop}${target.clientLeft}${target.clientWidth}${target.clientHeight}${target.offsetTop}${target.offsetLeft}`;
|
||||
};
|
||||
|
||||
kpxcFields.getElementFromXPathId = function(xpath) {
|
||||
return (new XPathEvaluator()).evaluate(xpath, document.documentElement, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
|
||||
|
|
@ -645,6 +667,12 @@ kpxcFields.useCustomLoginFields = async function() {
|
|||
kpxcTOTPIcons.newIcon(totp, kpxc.databaseState, true);
|
||||
}
|
||||
|
||||
// If not all expected fields are identified, return an empty combination
|
||||
if ((creds.username && !username) || (creds.password && !password) || (creds.totp && !totp)
|
||||
|| (creds.fields.length !== stringFields.length)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const combinations = [];
|
||||
combinations.push({
|
||||
username: username,
|
||||
|
|
@ -1161,10 +1189,15 @@ kpxc.initCombinations = async function(inputs = []) {
|
|||
return [];
|
||||
}
|
||||
|
||||
const combinations = kpxcFields.isCustomLoginFieldsUsed()
|
||||
const isCustomLoginFieldsUsed = kpxcFields.isCustomLoginFieldsUsed();
|
||||
const combinations = isCustomLoginFieldsUsed
|
||||
? await kpxcFields.useCustomLoginFields()
|
||||
: await kpxcFields.getAllCombinations(inputs);
|
||||
if (!combinations || combinations.length === 0) {
|
||||
if (isCustomLoginFieldsUsed) {
|
||||
kpxcUI.createNotification('warning', tr('optionsCustomFieldsNotFound'));
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue