I am trying to make an extension for Opera. I have an options page with options.js:
function saveOptions() {
localStorage.setItem("secret", document.getElementById("secret").value);
}
function restoreOptions() {
document.getElementById("secret").value = localStorage.getItem("secret") || '';
}
alert(localStorage.getItem("secret"));
restoreOptions();
document.querySelector("form").addEventListener("submit", saveOptions);
The alert shows the correct value for secret.
However, in the content script, the same alert line returns null. Why is this the case? How can it work on one page, but not on the other? How can I fix this?
LocalStorage data won't persist through domains.
You can use
chrome.storageas opera extensions are chromium based.https://developer.chrome.com/docs/extensions/reference/storage/