mirror of
https://github.com/keepassxreboot/keepassxc-browser.git
synced 2026-03-11 08:54:43 +00:00
Merge pull request #1877 from keepassxreboot/fix/add_undefined_checks
Modify checks for page.tabs
This commit is contained in:
commit
7bb0f83271
5 changed files with 23 additions and 27 deletions
|
|
@ -47,7 +47,7 @@ browserAction.showDefault = async function(tab) {
|
|||
tab = tabs[0];
|
||||
}
|
||||
|
||||
if (page.tabs[tab.id] && page.tabs[tab.id].loginList.length > 0) {
|
||||
if (page.tabs[tab.id]?.loginList.length > 0) {
|
||||
popupData.iconType = 'questionmark';
|
||||
popupData.popup = 'popup_login';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,9 @@ kpxcEvent.showStatus = async function(tab, configured, internalPoll) {
|
|||
browserAction.showDefault(tab);
|
||||
}
|
||||
|
||||
const errorMessage = page.tabs[tab.id].errorMessage;
|
||||
const errorMessage = page.tabs[tab.id]?.errorMessage ?? undefined;
|
||||
const usernameFieldDetected = page.tabs[tab.id]?.usernameFieldDetected ?? false;
|
||||
|
||||
return {
|
||||
identifier: keyId,
|
||||
configured: configured,
|
||||
|
|
@ -31,8 +33,8 @@ kpxcEvent.showStatus = async function(tab, configured, internalPoll) {
|
|||
keePassXCAvailable: keepass.isKeePassXCAvailable,
|
||||
encryptionKeyUnrecognized: keepass.isEncryptionKeyUnrecognized,
|
||||
associated: keepass.isAssociated(),
|
||||
error: errorMessage || null,
|
||||
usernameFieldDetected: page.tabs[tab.id].usernameFieldDetected,
|
||||
error: errorMessage,
|
||||
usernameFieldDetected: usernameFieldDetected,
|
||||
showGettingStartedGuideAlert: page.settings.showGettingStartedGuideAlert,
|
||||
showTroubleshootingGuideAlert: page.settings.showTroubleshootingGuideAlert
|
||||
};
|
||||
|
|
|
|||
|
|
@ -112,9 +112,7 @@ keepass.retrieveCredentials = async function(tab, args = []) {
|
|||
return [];
|
||||
}
|
||||
|
||||
if (tab && page.tabs[tab.id]) {
|
||||
page.tabs[tab.id].errorMessage = null;
|
||||
}
|
||||
keepass.clearErrorMessage(tab);
|
||||
|
||||
if (!keepass.isConnected) {
|
||||
return [];
|
||||
|
|
@ -223,9 +221,7 @@ keepass.associate = async function(tab) {
|
|||
return AssociatedAction.NOT_ASSOCIATED;
|
||||
}
|
||||
|
||||
if (tab && page.tabs[tab.id]) {
|
||||
page.tabs[tab.id].errorMessage = null;
|
||||
}
|
||||
keepass.clearErrorMessage(tab);
|
||||
|
||||
const kpAction = kpActions.ASSOCIATE;
|
||||
const key = nacl.util.encodeBase64(keepass.keyPair.publicKey);
|
||||
|
|
@ -261,9 +257,7 @@ keepass.associate = async function(tab) {
|
|||
};
|
||||
|
||||
keepass.testAssociation = async function(tab, args = []) {
|
||||
if (tab && page.tabs[tab.id]) {
|
||||
page.tabs[tab.id].errorMessage = null;
|
||||
}
|
||||
keepass.clearErrorMessage(tab);
|
||||
|
||||
try {
|
||||
const [ enableTimeout = false, triggerUnlock = false ] = args;
|
||||
|
|
@ -316,9 +310,7 @@ keepass.testAssociation = async function(tab, args = []) {
|
|||
keepass.handleError(tab, kpErrors.ASSOCIATION_FAILED);
|
||||
} else {
|
||||
keepass.isEncryptionKeyUnrecognized = false;
|
||||
if (tab && page.tabs[tab.id]) {
|
||||
delete page.tabs[tab.id].errorMessage;
|
||||
}
|
||||
keepass.clearErrorMessage(tab);
|
||||
}
|
||||
|
||||
return keepass.isAssociated();
|
||||
|
|
@ -492,9 +484,7 @@ keepass.getDatabaseGroups = async function(tab) {
|
|||
return [];
|
||||
}
|
||||
|
||||
if (tab && page.tabs[tab.id]) {
|
||||
page.tabs[tab.id].errorMessage = null;
|
||||
}
|
||||
keepass.clearErrorMessage(tab);
|
||||
|
||||
if (!keepass.isConnected) {
|
||||
return [];
|
||||
|
|
@ -534,9 +524,7 @@ keepass.createNewGroup = async function(tab, args = []) {
|
|||
return [];
|
||||
}
|
||||
|
||||
if (tab && page.tabs[tab.id]) {
|
||||
page.tabs[tab.id].errorMessage = null;
|
||||
}
|
||||
keepass.clearErrorMessage(tab);
|
||||
|
||||
if (!keepass.isConnected) {
|
||||
return [];
|
||||
|
|
@ -758,8 +746,8 @@ keepass.reconnect = async function(tab, connectionTimeout) {
|
|||
}
|
||||
|
||||
const hash = await keepass.getDatabaseHash(tab);
|
||||
if (hash !== '' && tab && page.tabs[tab.id]) {
|
||||
delete page.tabs[tab.id].errorMessage;
|
||||
if (hash !== '') {
|
||||
keepass.clearErrorMessage(tab);
|
||||
}
|
||||
|
||||
await keepass.testAssociation();
|
||||
|
|
@ -845,6 +833,12 @@ keepass.checkForNewKeePassXCVersion = function() {
|
|||
keepass.latestKeePassXC.lastChecked = new Date().valueOf();
|
||||
};
|
||||
|
||||
keepass.clearErrorMessage = function(tab) {
|
||||
if (tab && page.tabs[tab.id]) {
|
||||
page.tabs[tab.id].errorMessage = undefined;
|
||||
}
|
||||
};
|
||||
|
||||
keepass.handleError = function(tab, errorCode, errorMessage = '') {
|
||||
if (errorMessage.length === 0) {
|
||||
errorMessage = kpErrors.getError(errorCode);
|
||||
|
|
|
|||
|
|
@ -302,7 +302,7 @@ page.createTabEntry = function(tabId) {
|
|||
// If the retrieval is forced (from Credential Banner), get new credentials normally.
|
||||
page.retrieveCredentials = async function(tab, args = []) {
|
||||
const [ url, submitUrl, force ] = args;
|
||||
if (page.tabs[tab.id] && page.tabs[tab.id].credentials.length > 0 && !force) {
|
||||
if (page.tabs[tab.id]?.credentials.length > 0 && !force) {
|
||||
return page.tabs[tab.id].credentials;
|
||||
}
|
||||
|
||||
|
|
@ -380,7 +380,7 @@ page.getLoginList = async function(tab) {
|
|||
};
|
||||
|
||||
page.fillHttpAuth = async function(tab, credentials) {
|
||||
if (page.tabs[tab.id] && page.tabs[tab.id].loginList.resolve) {
|
||||
if (page.tabs[tab.id]?.loginList.resolve) {
|
||||
page.tabs[tab.id].loginList.resolve({
|
||||
authCredentials: {
|
||||
username: credentials.login,
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ function statusResponse(r) {
|
|||
} else if (!r.associated) {
|
||||
$('#need-reconfigure').show();
|
||||
$('#need-reconfigure-message').textContent = r.error;
|
||||
} else if (r.error !== null) {
|
||||
} else if (r.error) {
|
||||
$('#error-encountered').show();
|
||||
$('#error-message').textContent = r.error;
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in a new issue