localStorage different for webpage and chrome extension

前端 未结 1 804
情书的邮戳
情书的邮戳 2021-01-16 06:04

I\'m trying to access the localStorage object from my chrome extension\'s background.js file. The localStorage object on a regular web

相关标签:
1条回答
  • 2021-01-16 06:25

    The localStorage object is relative to the "local environment", this means that the localStorage object on http://www.google.com is totally different from the one on http://stackoverflow.com, and obviously is totally different from the one in the background page of your extension.

    Given that, if you want to store something in your extension, you'll need to use the localStorage object in your background page, not in the page of some site you are injecting content scripts to.

    If you want to access web pages' localStorages, then you'll have to send a content script on it, retrieve the localStorage object, and send it to the background.js script with a message (see chrome extensions message passing).

    Documentation on localStorage from MDN: here.

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