Note that there are some explanatory texts on larger screens.

plurals
  1. POlocalStorage is null on options page
    primarykey
    data
    text
    <p>In the options page of a chrome extension, localStorage is null and thus can not be used.<br> Here are the files of the unpacked extension producing error.</p> <h3>manifest.json</h3> <pre><code>{ "name": "someTest", "version": "1.0", "manifest_version": 2, "description": "Not important", "icons": { "16": "icon16.png", "48": "icon48.png" }, "options_page": "options.html" } </code></pre> <h3>options.html</h3> <pre><code>&lt;!doctype html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="UTF-8"&gt; &lt;title&gt;Just a test&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;script src="options.js"&gt;&lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <h3>options.js</h3> <pre><code>console.log(localStorage); </code></pre> <p>Accessing the options page, the console outputs <code>null</code>. When trying to change or access a property using <code>localStorage['property']</code>, it throws an error since localStorage is null.</p> <p>I tried something like <code>localStorage = {property: 'value'};</code> but it did not change anything, after that localStorage was still null.</p> <p>I'm using chrome 28.0.1500.95 on Windows 8.</p> <p><strong>Edit:</strong> The issue is still there. However, I -for the moment- use an alternative, if it can help someone. I now use chrome storage.</p> <p>Here is how it works.</p> <h3>manifest.json</h3> <pre><code>"permissions": ["storage"] </code></pre> <h3>options.js</h3> <pre><code>//You can also use an array of strings instead of 'property' to get multiple values. chrome.storage.local.get('property', function(data) { if(!data.propery) return; //Not set console.log(data.property); }); chrome.storage.local.set({property: 'value'}, function() { console.log('saved'); }); //It can be used the same way directly in content scripts. </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload