Save data to storage on popup close

I tried to save my changed data on popup close by calling chrome.storage.local.set on window.onunload, but it seems not to save the data. Is this intended not to work? If yes, is there any workaround?

You could see if you are still able to send messages to the background page. If that doesn’t work either, you could try the beforeunload event instead, or, if your “popup” is the browserAction panel, even the window.onblur event, after all, the blur closes the panel in Firefox.

If none of those work either, you can try to call a function directly in the background page to do the saving. Just be aware hat that won’t work with private windows.

1 Like

Yes I’m speaking about the browser action panal.
So I tried the onbeforeunload event, but in contrast to the unload event it never gets called.
However the onblur event or calling it directly in the background script seems to work nicely after some quick tests.

Thank you!

1 Like