1

I'm trying to save the email and the password of the user. What I'm missing here?

Here's my HTML:

<input type="text" name="email" id="email" placeholder="E-mail" />
<input type="password" name="password" id="password" placeholder="Password" />
<button id="import">Import!</button>
<script type="text/javascript" src="popup.js"></script>

Here's my JavaScript:

chrome.storage.local.get('email', function(result) {
    document.getElementById("email").value = result.value;
});

chrome.storage.local.get('password', function(result) {
    document.getElementById("password").value = result.value;
});

document.getElementById("import").addEventListener("click", function() {
    chrome.storage.local.set({'email': document.getElementById("email").value});
    chrome.storage.local.set({'password': document.getElementById("password").value});
}

Strangly, when I refresh the page, the values are not being kept.

  • [watch here](https://stackoverflow.com/questions/13872542/chrome-chrome-storage-local-get-and-set) Any help here? – Constantine Jul 13 '17 at 11:46
  • When I tried `console.log(result)` I realized, that the `chrome.storage.local.get` actually returns an object with no `value`. I'll post the answer. – Samurai Labs Jul 13 '17 at 12:41

1 Answers1

0

It should be:

chrome.storage.local.get('email', function(result) {
    document.getElementById("email").value = result.email;
});

chrome.storage.local.get('password', function(result) {
    document.getElementById("password").value = result.password;
});