0

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.

4
  • The solution is the same as for one of the existing answers. Commented Jul 29, 2024 at 23:01
  • @woxxom: So, I just noticed that question... but - the solution is not exactly the same, since chrome doesn't work in other apps. Shall I leave this question as is, or shall I adapt it to focus on the difference? Commented Jul 30, 2024 at 7:32
  • chrome is available in Thunderbird as well as in Firefox. It contains the callback-based version of the API compatible with chrome extensions, including chrome.runtime.getManifest. Commented Jul 30, 2024 at 9:12
  • @woxxom: Ok, flagged this as a dupe then. Commented Jul 30, 2024 at 9:17

1 Answer 1

0

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
})();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.