Reputation: 31
i am designing a chrome extension that gets Email from user. each time that user close the browser the value of Email will be lost. can i define a static variable? i need an unchangeable variable.
Upvotes: 1
Views: 726
Reputation: 77523
Another option, though outdated, is to use localStorage
in your extension's pages, like the background page and the popup.
An advantage of that method is synchronous access.
However, it is not available to content scripts (or rather, content scripts share localStorage with the page), and you have to serialize values yourself. chrome.storage
was made to address those limitations.
Edit: take a look at this question for a comparison.
Upvotes: 0
Reputation: 423
You can save it to extensions storage https://developer.chrome.com/extensions/storage
// Save it using the Chrome extension storage API.
chrome.storage.sync.set({'value': theValue}, function() {
// Notify that we saved.
message('Settings saved');
});
Upvotes: 3