1

Values set in local storage in background.html could not be accessed in javascripts loaded using content_script entry of manifest.json and vice versa. is this the default function of localstorage ? or am i missing something.

For example if i storing a value from myscript.js which is injected for each page load that could be accessible within myscript.js when i tried to access that in background.html it says undefined.

The same happens when i set a localstorage in background.html and try to accesss in myscript.js i couldn't were as it can be accessed in the page or script where it has been created or set.

Is this the default behavior or am in missing something?

Jayapal Chandran
  • 10,600
  • 14
  • 66
  • 91
  • Also see http://stackoverflow.com/questions/3937000/chrome-extension-accessing-localstorage-in-content-script – studgeek Jun 18 '14 at 00:49

1 Answers1

1

This is the default behaviour.

Content scripts injected into normal webpages can't access your extension's local storage.

And your extension's manifest can't access local storage, either.

Also see Do popup.html and background.html share the same local storage?

Community
  • 1
  • 1
Chris McFarland
  • 6,059
  • 5
  • 43
  • 63
  • So when ever we need a localstorage value we need to use sendrequest to fetch any value. and is we are saving values in localstorage from content_scripts what will be the scope... accessible with respect to the domain... that is will the scope be restricted to each domain we open? – Jayapal Chandran Jul 07 '11 at 12:31
  • i mean a variable var sam set for abc.com will be local to abc.com and a variable var sam set for xyz.com will be local for xyz.com... is it so? – Jayapal Chandran Jul 07 '11 at 12:32
  • From what I understand, injected content scripts can't access local storage at all. So yes, you'd need to use message passing to talk to your background page to set or retrieve variables. Be sure to read about content scripts' limitations: http://code.google.com/chrome/extensions/content_scripts.html – Chris McFarland Jul 07 '11 at 22:51