I want to transfer value from popup.js to content.js.
Overall, it works. But I can’t do “live” change, because content.js loads old value of chrome.storage.
popup.js
button.addEventListener('click', () => {
chrome.storage.sync.set({
text: form.textContent, // form.textContent = "1"
});
});
chrome.storage.sync.get(["text"]).then((result) => {
pageText.textContent = result.text; // result.text = "2"
});
content.js
function getInterval() { //test
chrome.storage.sync.get(["text"]).then((result) => {
pageText.textContent = result.text; //result.text = "1"
});
}
Initially result.text (storage) is “1”, saved from previous time;
I change value in popup to “2”.
If I try to read it via sync.get in popup.js I get it as “2”
But when I try to read it from content.js its “1”
But if I refresh tab, result.text = 2 in content.js.
Can you help me fix this?