So I'm creating a new tab in my background.js (Web extension) and I'm trying to set its localsotrage from content script after creating it. this is my background.js script :
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
if (message.from == "content") {
chrome.tabs.create({
url:message.url,
active:true
},function(tab){
sendResponse({access: "yes"});
console.log("callback function");
chrome.tabs.sendMessage(tab.id, { message: 'background' });
});
}
});
the tab is creating, and this is my content script function to listen to my background script after creating the new tab :
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
console.log('msg recu');
if (message.msg == 'background') {
localStorage.setItem("test","test");
}
});
Unfortunately, the localstorage is not setting. Am I doing something wrong ?