cookie or localStorage with chrome extensions

后端 未结 4 1463
我在风中等你
我在风中等你 2020-12-21 09:21

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

相关标签:
4条回答
  • 2020-12-21 10:01

    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.

    0 讨论(0)
  • 2020-12-21 10:05

    You do not want to use cookies when localstorage can do. That is because

    • Cookies can be accessed/modified through background page only.
    • Cookies are stored in context of a url/domain and not extension. So you will have to store a cookie for every domain that you wish to operate upon.
    • With every HttpRequest all the cookies associated with corresponding url/domain gets transmitted to server, so in effect you will be adding overhead to user's requests.)
    0 讨论(0)
  • 2020-12-21 10:15

    Please see the information on Chrome content scripts. I'm betting you fell into the same initial trap that I did -- trying to read localStorage from an page-injected script, yes?

    0 讨论(0)
  • 2020-12-21 10:27

    Use chrome.storage.local instead of localstorage. Content scripts using chrome.storage see the same thing that the extension page sees. More at https://developer.chrome.com/extensions/storage.html

    0 讨论(0)
提交回复
热议问题