A
A
Andrey Galko2015-09-11 12:04:33
Opera
Andrey Galko, 2015-09-11 12:04:33

Why don't all scripts in chrome extension get data from localstorage?

I'm writing an extension for myself. We need to store some data in localstorage. There are scripts that work with the content of the page and scripts that are responsible for the pop-up window (when clicking on the extension icon) and write data to localstorage.
So, I write data to localstorage and try to access the storage through scripts responsible for the content, but instead of values ​​they get just null, although everything is done within the framework of one extension and its scripts. Don't tell me what happened?
Here is the manifest:

{
   "content_scripts": [ {
      "persistent": true,
      "js": [ "jquery.js", "background.js", "inject.js" ],
      "matches": [ "http://*/*", "https://*/*" ],
      "run_at": "document_end"
   } ],
   "description": "Описание",
   "homepage_url": "http://example.com",
   "icons": {
      "128": "128.png"
   },
   "background": {
      "persistent": true,
      "scripts": ["jquery.js", "background.js"]
   },
   "manifest_version": 2,
   "name": "ADMINEX",
   "permissions": [ "background", "storage", "tabs", "alarms", "http://*/*", "https://*/*" ],
   "version": "1.1",
   "browser_action": {
        "default_title": "EXTNAME",
        "default_icon": "128.png",
        "default_popup": "popup.html"
    },
}

So I write and get:
localStorage.setItem('iswork', '1'); //запись
localStorage.getItem('iswork'); // получение

Normally, only script.js and background.js work with the repository (and that, somehow strange). What could it be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Ineshin, 2015-09-11
@IonDen

localStorage can be disabled, or automatically erased if you are in incognito browser mode. Maybe it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question