0

I will try my best to explain this.

I am developing a chrome extension that substitutes the new tab page. On this new tab page the user is able to give some information about him or herself and it is saved in chrome.storage.sync.

This new tab page has a background image that changes and grabs the image by making an API request.

Now... I want to be able to change the image AKA MAKE THE API REQUEST, even when the user is not currently on a "new tab page" (e.g. do the API request while he or she is watching a youtube video).

Now for this I would need an eventPage.js (background.js in the past). This much I know.

However, the API request takes in some parameters depending on the users information. So I need to go get the information.

Now how would I access from the eventPage.js -> chrome.storage.local when the user is on another page? I did inspect with storageAreaExplorerwhen I am on another page that is not a new tab page and I can NOT see the users information. And I also think this is why my eventPage.js can not make the API call. Is there away so that localStorage is available to the eventPage.js even when the user is not on the new tab page?

Walter Monecke
  • 2,386
  • 1
  • 19
  • 52
  • Relevant: https://stackoverflow.com/questions/14008580/localstorage-returning-null-in-a-different-tab-in-chrome – Lincoln Bergeson May 22 '17 at 17:18
  • @LincolnBergeson he is using the localStorage API. However, I am using chrome.storage as it says in the answer so it is not really helping me. Thank you tho! – Walter Monecke May 22 '17 at 17:23
  • If you are storing with sync, you should retrieve them from there, not local. chrome.storage.sync.get(key, callback) – juvian May 22 '17 at 17:34
  • seems you are just using an incorrect api. – Zig Mandel May 22 '17 at 21:50
  • Event page is a separate page which you can inspect through chrome://extensions in developer mode, it always can access own chrome.storage. Without seeing the actual code I can only assume you don't understand the [extension architecture](https://developer.chrome.com/extensions/overview#arch). – wOxxOm May 23 '17 at 02:24
  • @juvian sorry I do use the same sync storage to get the user info. Its a typo. – Walter Monecke May 23 '17 at 10:18
  • @WalterMonecke do chrome.storage.sync.get(null, console.log) to check if something has been stored – juvian May 23 '17 at 14:02

0 Answers0