diff --git a/src/background.js b/src/background.js index bf992bf..b228215 100644 --- a/src/background.js +++ b/src/background.js @@ -58,17 +58,30 @@ function getManagedAccounts(tabId) { }); } +function testUrlWithRegex(url, regexPattern) { + try { + const regex = new RegExp(regexPattern); + return regex.test(url); + } catch (error) { + alert(`testUrlWithRegex() error, the regex pattern: "${regexPattern}" is invalid`); + return false; + } +} + async function autoLogin(tabId, url) { const managedAccounts = await getManagedAccounts(tabId); if (managedAccounts) { for (const managedAccount of managedAccounts) { - if (managedAccount && url.includes(managedAccount.signinUrl)) { - autoLoginTabs.add(tabId); - chrome.tabs.sendMessage(tabId, { - action: "autoLogin", - managedAccount: managedAccount, - }); - break; + if (managedAccount && managedAccount.signinUrl && url) { + const isMatch = testUrlWithRegex(url, managedAccount.signinUrl); + if (isMatch) { + autoLoginTabs.add(tabId); + chrome.tabs.sendMessage(tabId, { + action: "autoLogin", + managedAccount: managedAccount, + }); + break; + } } } }