1

In my popup.html, I have this

<script src="popup.js"></script>

so then in my popup.js I try to run

chrome.storage.sync.set({"testkey": 'test'});

I got error of Uncaught TypeError: Cannot read property 'sync' of undefined

I'd declare my permission properly :

  "permissions": [
    "http://*/*", "https://*/*","storage"
  ],
  "browser_action": {
      "default_icon": "icon.png",
      "default_popup": "popup.html"
  }
Aaron Musktin
  • 297
  • 3
  • 12
  • Have you reloaded your extension properly after changing the manifest? Have you **double**-checked for typos? Are you by any chance trying to load `popup.html` outside the extension? – Xan May 12 '15 at 14:38
  • 1
    I reloaded and it worked, wierd when should I reload and when I need no to reload? because sometime I didn't reload I still see the changes I made. – Aaron Musktin May 12 '15 at 15:02
  • Rule of thumb, _always_ reload after changes. Changes to HTML files do not require a reload since Chrome re-reads them, but changing most scripts requires a reload. And in case of content scripts - also a reload of the target page. And changes to the manifest also require reloads. – Xan May 12 '15 at 15:03
  • @Xan thanks, got it. Can you take a look at this question please? http://stackoverflow.com/questions/30195606/chrome-extension-got-blank-object-using-chrome-storage-sync-get – Aaron Musktin May 12 '15 at 15:42

1 Answers1

-2

Is it possible that it is trying to cal it before storage exists. try a

setTimeout('chrome.storage.sync.set({"testkey": 'test'});', 150);

to set it off after a delay to make sure it isn't related to load. only thing is it will run that in global(window) scope. not sure if that matters.

Sarfaraaz
  • 488
  • 6
  • 17