Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrom Extension: Close event not available on SidePanel closure

I need to clear out my chrome storage which is being managed when the sidepanel opens up. But there are no click event available for close button of a sidepanel.

The close button I'm referring is as below in a sidepanel

enter image description here

There is a port connection way mentioned over here but I could get it working with my set of requirements. I need to accomplish this in a background.js file

like image 945
Matey Johnson Avatar asked Sep 05 '25 08:09

Matey Johnson


1 Answers

This is my working code:

sidebar.js

chrome.runtime.connect({ name: 'mySidepanel' });

background.js:

chrome.runtime.onConnect.addListener(function (port) {
  if (port.name === 'mySidepanel') {
    port.onDisconnect.addListener(async () => {
      console.log('Sidepanel closed.');
    });
  }
});
like image 116
Latz Avatar answered Sep 09 '25 04:09

Latz