einpoklum
einpoklum

Reputation: 132128

In a WebExtension's background.js script, how can I access values from manifest.json?

Suppose I'm maintaining a WebExtension, with a Manifest V2 file. My extension has a background.js script which sets all sorts of things up. Now, I want to access arbitrary key-value pairs from my extension's manifest.json file, within the background.js script.

Is this possible? If so, how do I do that?

Note: In case it matters, the app is Thunderbird; and I'm not really maintaining a WebExtension, but that's complicated and out of scope.

Upvotes: 0

Views: 56

Answers (1)

einpoklum
einpoklum

Reputation: 132128

Depending on the application your background script is running in, you can use either chrome.runtime.getManifest() or browser.runtime.getManifest().

Specifically, this works in a thunderbird background

(async function () {
  let manifest = browser.runtime.getManifest();
  console.log(manifest.name); // will log the name of your WebExtension
  // ... rest of your code
})();

Upvotes: 0

Related Questions