I'm trying to create a chrome extension which has a form where I take notes.
Say I'm reading Wikipedia. Whilst reading I want to open the extension popup, paste/write something, close the popup, read some more, open the popup, past/write some more.
At the end, I'd hit submit and send the data to API.
Every time the popup closes though the data on the form is gone. So I thought, on popup closing, I'd add the data to local storage (not sure if there's another way)
So I'm trying to use the background script.
In the manifest file
"background": {
"scripts": ["background.js"],
"persistent": false
}
And in the background.js
chrome.runtime.onConnect.addListener(function(externalPort) {
externalPort.onDisconnect.addListener(function() {
console.log("onDisconnect - nothing logs");
localStorage.setItem("test", "test");
});
console.log("onConnect - nothing logs");
});
console.log("this logs")
That doesn't work. All the research led me to chrome.runtime.onConnect.addListener
but there's no response at all, (the background.js
is linked correctly)