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
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
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.');
});
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With