1

As many said, the global variable will be no longer valid in V3 because the service worker script will be unloaded after the event is processed.

However, I read that there's a new update in Feb 2022 which says that, (https://developer.chrome.com/docs/extensions/whatsnew/)

Connecting to a native messaging host using chrome.runtime.connectNative() in an extension's service worker will keep the service worker alive as long as the port is open.

Which means there are indeed some circumstances under which the service worker will be kept alive across multiple events.

So can I assume that all global variables (not only the native ports) will be valid as long as the service worker is alive?

Thanks.

Chou Tan
  • 85
  • 6
  • 1) Nothing's changed: global variables were always valid as long as service worker is alive. 2) That update is bugged and actually doesn't work. 3) See [Persistent Service Worker in Chrome Extension](https://stackoverflow.com/a/66618269) – wOxxOm May 23 '22 at 11:28

0 Answers0