Retrieving preferences in WebExtension addon

I have this code:

      function setCurrentDomain(result) {
        console.log(result);
        domainExclude  = result.domain;
        console.log("Domain " + domainExclude);
      }
      function setCurrentVersion(result) {
        console.log(result);
        versionHeader = result.version;
        console.log("Version " + versionHeader);
      }
      function onError(error) {
          console.log(`Error: ${error}`);
        }
    console.log("Start Main");
    var getting = browser.storage.local.get("version");
    getting.then(setCurrentVersion, onError);
    var getting = browser.storage.local.get("domain");
    getting.then(setCurrentDomain, onError);

The variable domainExclude is set correctly and the variable versionHeader is undefined. I can’t see any difference in the code of the two functions or any error in the file containing the values that should be given.

Does anyone have any ideas?

Could you please, please use code blocks so your code is more readable on this forum?

Based on your code my assumption would be that version is not set. Have you checked the output when you just get everything in your local storage? Just do browser.storage.local.get() to retrieve everything.

Sorry Martin. I couldn’t see how to do code blocks. :frowning:

When I tried your get all code - it just showed me the domain and not the version… The really annoying thing is that I think it’s a bug with Thunderbird - it’s a Thunderbird addon and I can’t find where the data is being stored. I’ve looked in the managed storage address and I’ve looked for files that have been changed after changing the domain but I just can’t find it. So I can’t change it programatically which is what I want to do. I even looked in prefs.js!

Thanks for your response.
Blessings

As mentioned before, either use the </> button in the toolbar of the editor or three ` at the start and the end of the code (markdown/github style).

If version is not in the results of everything it wasn’t set. It’s that simple.

The storage works exactly the same in Firefox and Thunderbird. Usually it will be a js file, in the future it will be indexedDB though.

What I really want to know now is where it is saved. It is not in the json file that is referenced in the registry. So where is it.
I want to set the version outside of Thunderbird so that it can be used in my addon. I thought it was working before but it seems to have changed.

Thanks for rapid responses.
Blessings

If you want to set things from the outside you should be using managed storage. Modifying storage.local from the outside is not supported.

Edit: also just noticed that this was posted in the end-user category, moved to development.

Thanks for your time.:slight_smile:

Just one last question on this - where is local.storage saved, in the same place as all profile data, like prefs.js is, or in app data or in program data?
Blessings

storage.local is in the profile, yes. Managed storage isn’t (https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/managed etc.)

Wonderful! Thanks!..