From 41b0a136a8c1887b4a2fdb40f89aea1cc3c7bfeb Mon Sep 17 00:00:00 2001 From: Patrick Sean Klein Date: Thu, 9 Jun 2022 22:35:33 +0200 Subject: [PATCH] Set currentTabId in remove tab. --- keepassxc-browser/background/init.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/keepassxc-browser/background/init.js b/keepassxc-browser/background/init.js index 09fe962..6d84218 100644 --- a/keepassxc-browser/background/init.js +++ b/keepassxc-browser/background/init.js @@ -37,11 +37,16 @@ browser.tabs.onCreated.addListener((tab) => { * @param {integer} tabId * @param {object} removeInfo */ -browser.tabs.onRemoved.addListener((tabId, removeInfo) => { - delete page.tabs[tabId]; +browser.tabs.onRemoved.addListener(async function(tabId, removeInfo) { if (page.currentTabId === tabId) { - page.currentTabId = -1; + const activeTabs = await browser.tabs.query({ active: true, currentWindow: true }); + if (activeTabs.length > 0) { + page.currentTabId = activeTabs[0].id; + } else { + page.currentTabId = -1; + } } + delete page.tabs[tabId]; }); /**