As everybody knows, we can't persist data in popup window.
I have to recover the data when the popup window is opened again. But this data is not static data. It's a count value which is incremented by one per second.
So, for instance, if we close the popup window when the count value is 5 and reopen the popup window after 5 seconds, the count value should be 10. But now I get the initial value 0.
To handle this, I tried to use Sync storage.
Interval is running on the background script. And in the popup script, we just get the storage value and render.
But I think it's very bad practice to set storage value in every interval.
So Any solution to solve this problem?
I am currently thinking how to detect the popup window is closed.
If we detect the popup window is closed, then we can run the interval on the background script and get the count value from background script when popup window is opened again.
chrome.runtime.onConnect.addListener(function (externalPort) {
externalPort.onDisconnect.addListener(function () {
console.log("Disconnect");
});
console.log("Connect")
})
I try like above. But it didn't work.
Please help me how to detect the popup window is destroyed.
Also it would be great for me to let me know any other solution.
Thanks in advance.