0

I am developing an extension which shows some values in popup. The values are fetched in event page script periodically.

function load() {
  var value = fetch();
  // I would like to set this value to popup content.
}

chrome.alarms.onAlarm.addListener(function(alarm) {
  if (alarm.name === "refresh") {
    load();
  }
});

chrome.alarms.create("refresh", {"periodInMinutes": 10});

I tried to get the popup window to change its content using chrome.extension.getViews({ViewType: "popup"}) in event page script but it returned an empty array.

I know I can do it using storage but it seems to me overkill.

So how can I use the value in popup?

wOxxOm
  • 65,848
  • 11
  • 132
  • 136
rch850
  • 710
  • 1
  • 5
  • 14
  • 1
    Popups simply don't exist when closed so use [messaging](https://developer.chrome.com/extensions/messaging) or, depending on the actual goal, [chrome.runtime.getBackgroundPage](https://developer.chrome.com/extensions/runtime#method-getBackgroundPage) (in the popup, not in the event page). – wOxxOm Jan 15 '17 at 16:49
  • Possible duplicate of [Chrome Extension sendMessage to pageAction](http://stackoverflow.com/questions/41420528/chrome-extension-sendmessage-to-pageaction) – Makyen Jan 15 '17 at 17:56
  • `value` is currently scoped to the `load()` function. If you want to access what `fetch()` returns from outside `load()` it needs to be assigned to a variable that has global scope. – Makyen Jan 15 '17 at 18:00
  • Why do you feel that using `chrome.storage.local` is overkill? – Makyen Jan 15 '17 at 18:01
  • Because I do not need the value is kept over sessions and I thought that adding permission `storage` introduces additional warning to user. But after trying to use `chrome.storage.local`, there were no such warning. I will use `chrome.storage.local`. – rch850 Jan 16 '17 at 14:45

0 Answers0