T
T
tipask2452020-11-23 22:02:07
JavaScript
tipask245, 2020-11-23 22:02:07

How to get chrome storage values ​​in content script?

In popup.js I store data in chrome storage

var mail = document.getElementById("mail").value;
chrome.storage.local.set({email: mail}, function() {
          console.log('Value is ' + mail);
});

In content-script.js I want to get this data
chrome.storage.local.get(['mail'], function(result) {
        console.log('Value currently is ' + result.mail);
});

In console.log it gives me Value currently is undefined
What should I do?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
tipask245, 2020-11-24
@tipask245

Everything, I found a mistake, it's my own fault

N
Nadim Zakirov, 2020-11-23
@zkrvndm

If you save content like this: Then I will tell you that it is not saved like this. Need like this:
var mail = document.getElementById("mail").value;

chrome.storage.local.set({mail: document.getElementById("mail").value}, function() {
    console.log('Сохранено' );
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question