popups have the same privileges as the background page. The only limitation is that they stop running when they’re closed. So if you do something async (promises) and close the popup while that’s still running there’s no guarantee it’ll complete.
What would be the best solution to make a settings page then?
I activated the option “Disable Popup auto-hide”. My entries did not appear in the storage manager while my console output with .then was working fine.
I am developing the whole thing for a subject paper in computer science for my Abitur (Germany) and it will be open-source, so you can just find my code here: https://github.com/Th3Ph4nt0m/Pius-Addon
I would be really grateful if we could find a reasonable solution together.
The best way to do a settings page is probably options ui.
But in general, it would be to save settings on blur of the input or similar, instead of requiring a submit.
Unfortunately, this is not possible in this case. The Options UI is actually very unknown, so many will not find the settings. To keep the UX as good as possible, everything should be found in one place, preferably in the pop-up.
I also cannot save the values, for example, when entering them, as 3 dropdowns result in one entry at the end.
My code should be correct though, if I’m not completely wrong. So I don’t understand why the entries are not set.
async function setSomeData() {
await browser.storage.local.set({a: 1});
const {a} = await browser.storage.local.get('a'); // getting back "a" using Destructuring assignment
console.log(a); // prints "1"
}
I have no idea what I am doing wrong here. The chrome api has a similar structure, so I only need to change browser to chrome. I have the same problem there.
Yeah, that’s right. I am using the storage inspector via the “Inspect” from “Debug Addons”. As you can see here, the console output is correct, but the storage inspector remains empty, even after reloading it manually.
Note that you are in a Popup context - maybe if you switch to background script context it would help.
Just like with multiple iframes in the page you can switch your current “view” to display a specific “context”, with the addon debugger you can also switch which part of your extension you want to debug. To do this, there is an icon in the upper right corner: https://developer.mozilla.org/en-US/docs/Tools/Browser_Toolbox#targeting_a_document