title: Is there any way to detect popup close for a Chrome Extension before the popup is closed?
body: <p>I know that <a href="https://stackoverflow.com/questions/15798516/is-there-an-event-for-when-a-chrome-extension-popup-is-closed">one can use ports</a> to detect popup close. However, this doesn't work when there is information on the popup that I wish to persist.</p>
  
  <p>For <a href="https://softwarerecs.stackexchange.com/a/1913/19">this extension</a> I need to be able to save the textarea contents to sync storage when the popup is closed. There already is an update button which manages this, but no way to temporarily halt and save the status if the popup gets (accidentally) closed.</p>
  
  <p>One way to do this is to keep storing the content on keypress, but I'd rather not hit the storage so often (especially since it's connected to some other event handlers).</p>
  
  <p>Is there any way I can mimic <code>onbeforeunload</code> for a popup without being too heavy on the I/O?</p>