diff --git a/keepassxc-browser/_locales/en/messages.json b/keepassxc-browser/_locales/en/messages.json index b58595d0..bff11360 100644 --- a/keepassxc-browser/_locales/en/messages.json +++ b/keepassxc-browser/_locales/en/messages.json @@ -1022,6 +1022,14 @@ "message": "Credentials are cleared from background tabs after the timeout and permissions for those pages will be asked again.", "description": "Clear credentials timeout help text." }, + "optionsConnectionTimeout": { + "message": "KeepassXC connection timeout: $1 seconds", + "description": "Connection timeout label text." + }, + "optionsConnectionTimeoutHelpText": { + "message": "When KeePassXC browser extension tries to connect to to keepass, this timeout value is used. Default value is 1.5. Maximum is 60.0.", + "description": "Connection timeout label text." + }, "optionsVersionInfoText": { "message": "KeePassXC-Browser needs KeePassXC to retrieve credentials.", "description": "Settings page version info text." diff --git a/keepassxc-browser/background/keepass.js b/keepassxc-browser/background/keepass.js index c1d13670..31ab97f0 100755 --- a/keepassxc-browser/background/keepass.js +++ b/keepassxc-browser/background/keepass.js @@ -804,7 +804,12 @@ keepass.disableAutomaticReconnect = function() { keepass.reconnectLoop = null; }; -keepass.reconnect = async function(tab = null, connectionTimeout = 1500) { +keepass.reconnect = async function(tab = null, connectionTimeout = CONNECTION_TIMEOUT) { + if (arguments.length < 2) { + connectionTimeout = page.settings.connectionTimeout; + } + + connectionTimeout = Math.min(60000, Math.max(CONNECTION_TIMEOUT, connectionTimeout)) keepassClient.connectToNative(); keepass.generateNewKeyPair(); const keyChangeResult = await keepass.changePublicKeys(tab, !!connectionTimeout, connectionTimeout).catch(() => false); diff --git a/keepassxc-browser/background/page.js b/keepassxc-browser/background/page.js index 4020a1b4..c2fce28b 100755 --- a/keepassxc-browser/background/page.js +++ b/keepassxc-browser/background/page.js @@ -14,6 +14,7 @@ const defaultSettings = { bannerPosition: BannerPosition.TOP, checkUpdateKeePassXC: CHECK_UPDATE_NEVER, clearCredentialsTimeout: 10, + connectionTimeout: CONNECTION_TIMEOUT, colorTheme: 'system', credentialSorting: SORT_BY_GROUP_AND_TITLE, debugLogging: false, @@ -47,6 +48,7 @@ page.autoSubmitPerformed = false; page.attributeMenuItems = []; page.blockedTabs = []; page.clearCredentialsTimeout = null; +page.connectionTimeout = null; page.currentRequest = {}; page.currentTabId = -1; page.isFirefox = false; diff --git a/keepassxc-browser/common/global.js b/keepassxc-browser/common/global.js index 10f58f60..bcf5a44a 100755 --- a/keepassxc-browser/common/global.js +++ b/keepassxc-browser/common/global.js @@ -24,6 +24,9 @@ const CHECK_UPDATE_THREE_DAYS = 3; const CHECK_UPDATE_ONE_WEEK = 7; const CHECK_UPDATE_ONE_MONTH = 30; +// Default value for connection timeout +const CONNECTION_TIMEOUT = 1500; + const URL_WILDCARD = '1kpxcwc1'; const schemeSegment = '(\\*|http|https|ws|wss|ftp)'; const hostSegment = '(\\*|(?:\\*\\.)?(?:[^/*]+))?'; diff --git a/keepassxc-browser/managed_storage.json b/keepassxc-browser/managed_storage.json index 21af9b8e..1db43692 100644 --- a/keepassxc-browser/managed_storage.json +++ b/keepassxc-browser/managed_storage.json @@ -52,6 +52,10 @@ "title": "Clear credential info from tabs after timeout. Default (seconds): 10", "type": "integer" }, + "connectionTimeout": { + "title": "Connection timeout to KeePassXC. Default (seconds): 1.5", + "type": "integer" + }, "colorTheme": { "title": "Extension color scheme. Default: system", "type": "string" diff --git a/keepassxc-browser/options/options.html b/keepassxc-browser/options/options.html index 4dd97d08..d8e672d5 100644 --- a/keepassxc-browser/options/options.html +++ b/keepassxc-browser/options/options.html @@ -531,6 +531,14 @@

+ + +
+ + +
+
+
diff --git a/keepassxc-browser/options/options.js b/keepassxc-browser/options/options.js index c5c5d28c..1202af31 100644 --- a/keepassxc-browser/options/options.js +++ b/keepassxc-browser/options/options.js @@ -114,7 +114,7 @@ options.initGeneralSettings = async function() { $('#tab-general-settings input[type=radio]#checkUpdateOneMonth').value = CHECK_UPDATE_ONE_MONTH; $('#tab-general-settings input[type=radio]#checkUpdateNever').value = CHECK_UPDATE_NEVER; - $('#tab-general-settings input[type=range]').value = options.settings['redirectAllowance']; + $('#tab-general-settings #redirectAllowance').value = options.settings['redirectAllowance']; $('#redirectAllowanceLabel').textContent = tr('optionsRedirectAllowance', options.settings['redirectAllowance'] === 11 ? 'Infinite' : String(options.settings['redirectAllowance'])); @@ -124,6 +124,9 @@ options.initGeneralSettings = async function() { $('#tab-general-settings input#defaultGroup').value = options.settings['defaultGroup']; $('#tab-general-settings input#defaultPasskeyGroup').value = options.settings['defaultPasskeyGroup']; $('#tab-general-settings input#clearCredentialTimeout').value = options.settings['clearCredentialsTimeout']; + const connectionTimeout = (options.settings['connectionTimeout']/1000); + $('#tab-general-settings input#connectionTimeout').value = connectionTimeout; + $('#connectionTimeoutLabel').textContent = tr('optionsConnectionTimeout', String(connectionTimeout)); const generalSettingsRadioInputs = document.querySelectorAll('#tab-general-settings input[type=radio]'); for (const radio of generalSettingsRadioInputs) { @@ -173,7 +176,17 @@ options.initGeneralSettings = async function() { }); // Change label text dynamically with the range input - $('#tab-general-settings input[type=range]').addEventListener('input', function(e) { + $('#tab-general-settings input#connectionTimeout').addEventListener('input', function(e) { + $('#connectionTimeoutLabel').textContent = tr('optionsConnectionTimeout', e.target.value); + }); + + $('#tab-general-settings input#connectionTimeout').addEventListener('change', async function(e) { + options.settings['connectionTimeout'] = Math.min(60000, Math.max(CONNECTION_TIMEOUT, e.target.valueAsNumber * 1000)) + await options.saveSettings(); + }); + + // Change label text dynamically with the range input + $('#tab-general-settings input#redirectAllowance').addEventListener('input', function(e) { const currentValue = e.target.valueAsNumber === 11 ? 'Infinite' : e.target.value; $('#redirectAllowanceLabel').textContent = tr('optionsRedirectAllowance', currentValue); }); @@ -726,7 +739,7 @@ options.initSitePreferences = function() { // Page URL row.children[0].children[0].children[0].value = url; - row.children[0].children[0]?.addEventListener('dblclick', (e) => + row.children[0].children[0]?.addEventListener('dblclick', (e) => enterEditMode(e, row, inputField, editButton, cancelButton, saveButton) ); @@ -891,7 +904,7 @@ const getBrowserId = function(userAgent) { return `${query.name} ${getVersion(userAgent, query.findStr)}`; } } - + return 'Other/Unknown'; }; @@ -919,7 +932,7 @@ const updateDropdownPosition = function(e, dropdown) { if (!rect) { return; } - + const zoom = getComputedStyle(document.body).zoom || 1; const scrollTop = document.defaultView.scrollY / zoom; const scrollLeft = document.defaultView?.scrollX / zoom;