C
C
Camaro672015-04-30 08:25:04
JavaScript
Camaro67, 2015-04-30 08:25:04

How to get data in content script directly from chrome.storage?

Hello!
Faced such a problem: you need to get data from chrome.storage in the content script.
I know that it is possible to receive the data from storage through messages. But I need a function that would result in data from the storage. Those. this option is not suitable:
Content script

function get_data() {
  chrome.runtime.sendMessage({}, function (data) {
    window.data = data;
  });
}

Background script
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
  if(!chrome.storage.local['data'])
    chrome.storage.local['data'] = 'Какие-то данные...';

  sendResponse(chrome.storage.local['data']);
});

Thank you in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Winout, 2015-08-12
@Winout

chrome.storage.local.get(null, function(r){
  alert(r["data"])
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question