diff --git a/README.md b/README.md index 923b8140..e9f9842e 100644 --- a/README.md +++ b/README.md @@ -87,8 +87,7 @@ Mullvad Browser Extension requires the following permissions: **Optional** -- `webRequest` to automatically login to Mullvad Leta (optional) -- `webRequestBlocking` to automatically login to Mullvad Leta (optional) +- `alarms` to automatically renew Mullvad Leta cookie (optional) _Permissions are automatically accepted when testing the extension._ diff --git a/package.json b/package.json index e5b09082..58ed5b2d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "mullvad-browser-extension", "displayName": "Mullvad Browser Extension", - "version": "0.8.0", + "version": "0.8.1", "description": "Improve your Mullvad VPN experience, in your browser.", "private": true, "engines": { diff --git a/src/background/main.ts b/src/background/main.ts index 1841e654..93aab49c 100644 --- a/src/background/main.ts +++ b/src/background/main.ts @@ -1,7 +1,13 @@ import { onMessage } from 'webext-bridge/background'; import { addExtListeners } from '@/helpers/extensions'; -import { DataAccount, initLetaLogin, letaLogin, letaLogout } from '@/helpers/leta'; +import { + DataAccount, + getMullvadAccount, + initLetaLogin, + letaLogin, + letaLogout, +} from '@/helpers/leta'; // only on dev mode if (import.meta.hot) { @@ -25,6 +31,22 @@ onMessage('leta-logout', () => { letaLogout(); }); +// Alarm to refresh Mullvad Leta auth cookie +// The cookie expires after 24h, so renewal is set for every 23h +browser.alarms.create('leta-cookie-refresh', { + delayInMinutes: 1380, + periodInMinutes: 1380, +}); + +const refreshCookie = async (alarm: browser.alarms.Alarm) => { + if (alarm.name === 'leta-cookie-refresh') { + const account = await getMullvadAccount(); + await letaLogin(account); + } +}; + +browser.alarms.onAlarm.addListener(refreshCookie); + // `browser.cookies` operations are only available in the background context export const setCookie = async (cookie: browser.cookies._SetDetails) => { try { diff --git a/src/components/LetaSettings.vue b/src/components/LetaSettings.vue index 909f6cb0..193f2078 100644 --- a/src/components/LetaSettings.vue +++ b/src/components/LetaSettings.vue @@ -1,5 +1,5 @@