With the release of v2.0.16, AdGuard VPN Browser Extension became one of the first VPN extensions to migrate to Manifest V3! The new Chrome API version has become a stumbling block for many developers. It makes significant changes to the rules that browser extensions must follow.
Moving to this new API presented some challenges. The main one was related to the appearance of the service worker which replaced the background page.
The peculiarity of the latter is that it periodically falls asleep. More specifically, when the extension is not in use and there are no events or API calls to extend the service worker's life, the browser suspends service worker’s operation.
This behavior is intended to significantly reduce system power consumption. However, for the AdGuard VPN Browser Extension, designed to assist users continuously, the regular deactivation of the service worker caused numerous problems and delays.
To manage the service worker lifecycle, we:
moved the event listener registration to the top level of the code and made it
synchronous used the Alarm API
added a session storage module to quickly restore the service worker on waking up
There were two more issues related with service worker:
There is currently no way to use NetworkConnectionObserver
that monitors network status (online/offline
) and helps determine why an app isn't receiving server responses. It also monitors transitions from offline to online, checking access rights and re-establishing the connection if it was established before going offline.
The service worker lacks window
access, complicating implementation of NetworkConnectionObserver
. A possible solution – using an offscreen document – may run into problems in the future, as Google plans to put the offscreen document to sleep after inactivity, as well as the service worker. The current workaround involves checking navigator.online
state every half second and calling callback if it transitions from offline to online
.
Messages received by the extension over a websocket connection do not wake up the sleeping service worker. But here we need to wait for Chrome to fix this
bug.
We’ve also fixed an issue with a browser popup requesting proxy authorization. This used to happen when the session storage wasn't able to load the credentials before the
onAuthRequired
event handler fired at the service worker wakeup. To fix this, we've added an asynchronous callback for the
onAuthRequired
handler. It is now set to wait until the session storage has loaded the credentials and entered them.
Changelog
Features
Added a country code search in ISO format
#85 Fixes
The
ESC
button does not work in the drop-down lists of the
Settings section
#90 Browser icons in the
Add another device section (
Free GB tab) confuse users
#98 Login to the extension via "Thank you" page after installation does not work
#99