Pre: I'm in chrome and logged in
- I launch (click on) my popup window. It saves some data in all storages (windowlocal, windowsession, google local and google sync)
- I right click on it, and choose inspect.
- The dev tools window comes up for the popup
- I look in Storage Explorer in Dev Tools, I see all my data is there, in all storages.
![enter image description here](https://i.sstatic.net/E7c7W.png)
- I put a breakpoint at the start of my popup.js code. This breakpoint is before it loads any data or does anything. It's at the beginning of the constructor.
- I hit F5 on the Dev Tools window. It flickers and comes back
Expected Result: I see all the data I've saved
Actual Result: No data whatsoever is there, in any of the storages. It's all gone.
What am I doing wrong? Is popup not supposed to be able to save data?
Issues
- If you put a breakpoint in the constructor of an extension on dev tools, it's likely that storage explorer won't show anything, because it hasn't loaded yet
- In my constructor, I was loading the settings correctly from storage, but then immediately overwriting them with the default values because I was calling load() first, and it had become asynchronous, and further down in my code in my settings property setters were re-saving the default values, so by the time load() resolved itself to execute, it was just reading the (just) saved default values.
Solution
I brought the load code out of the constructor into an async
function, and called that function right at the end of my constructor. In that function, I used await
to make sure the settings were loaded from storage, then continued to set the settings properties.