0

I have some constants in my extension that need to be accessed by both the popup script and the background script. Right now I'm duplicating these declarations in both.

I know I can pass messages between the scripts, but that would obviously be nonsensical - this is purely static information, and I merely want to avoid potential errors from having two sources of truth.

Is there any way to make static declarations in a place that all different parts of a Chrome extension have read access to? Or is there a different way this should be handled?

Krateng
  • 388
  • 1
  • 3
  • 13
  • If they are _constant_ why can't you move the definitions into a script and import/include the latter from wherever you need to access these? – Armen Michaeli Nov 24 '22 at 19:01

1 Answers1

1

If you're using manifest V3 you can use chrome.storage.session to save and retrieve those values.
If you're using manifest V2, you can get those values from the popup script via chrome.runtime.getBackgroundPage()

syncmate
  • 160
  • 9
  • I honestly don't understand what the thread reported by the moderator has in relation to the @Krateng question and therefore I don't understand why this thread was closed. – syncmate Nov 24 '22 at 19:34