Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cookie or localStorage with chrome extensions

I've read all the other q's here regarding the topic but couldn't solve my problem.
I'm setting on my website the email of the user in the localStorage and i want to retrieve it in the extension.

localStorage.setItem("user", "[email protected]" ); 

But when i try to receive it with the chrome extension it fails to do so

value = localStorage.getItem("user");

Which way is easier ? cookies localstorage ? im not pretentious

like image 705
andrei Avatar asked Aug 30 '10 07:08

andrei


People also ask

Can Chrome extensions use localStorage?

One way to share data between a background script and the other scripts that make up the extension is to save the data to a location which is accessible to all the scripts in the extension. We can use the browser localStorage API or chrome. storage which is specific to Chrome extensions.

Should I use local storage or cookie?

If you need to store data that is accessible for both the server and the client, use cookies. Otherwise, use local storage. If you need to store larger data, use local storage. If you need to store data that does not expire, use local storage.

Which is safer cookie or localStorage?

Conclusion. Both cookies and localStorage are vulnerable to XSS attacks. However, cookie-based token storage is more likely to mitigate these types of attacks if implemented securely. The OWASP community recommends storing tokens using cookies because of its many secure configuration options.

Where do Chrome extensions save data?

When extensions are installed into Chrome they are extracted into the C:\Users\[login_name]\AppData\Local\Google\Chrome\User Data\Default\Extensions folder. Each extension will be stored in its own folder named after the ID of the extension.


1 Answers

Please see this:

http://code.google.com/chrome/extensions/content_scripts.html#host-page-communication

Content scripts are run in a separate JavaScript world, which means the content script's localStorage is different from the website's localStorage. The only thing the two share is the DOM, so you'll need to use DOM nodes/events to communicate.

like image 129
Pauan Avatar answered Sep 28 '22 16:09

Pauan