In the options page of a chrome extension, localStorage is null and thus can not be used.
Here are the files of the unpacked extension producing error.
{
"name": "someTest",
"version": "1.0",
"manifest_version": 2,
"description": "Not important",
"icons": {
"16": "icon16.png",
"48": "icon48.png"
},
"options_page": "options.html"
}
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Just a test</title>
</head>
<body>
<script src="options.js"></script>
</body>
</html>
console.log(localStorage);
Accessing the options page, the console outputs null
. When trying to change or access a property using localStorage['property']
, it throws an error since localStorage is null.
I tried something like localStorage = {property: 'value'};
but it did not change anything, after that localStorage was still null.
I'm using chrome 28.0.1500.95 on Windows 8.
Edit: The issue is still there. However, I -for the moment- use an alternative, if it can help someone. I now use chrome storage.
Here is how it works.
"permissions": ["storage"]
//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.
I select an element of the page: $mainSection = $('#main'); then I add more Elements via AJAX into the <div id="main"></div> element. Next time I call $mainSection, the newly added ...
I select an element of the page: $mainSection = $('#main'); then I add more Elements via AJAX into the <div id="main"></div> element. Next time I call $mainSection, the newly added ...
I have built a website but really struggling with easyslider and Internet explorer. It seems the Javascript is loading and then deciding against it for some reason. jQuery is included in the header ...
I have built a website but really struggling with easyslider and Internet explorer. It seems the Javascript is loading and then deciding against it for some reason. jQuery is included in the header ...
chart3 = new Highcharts.Chart({ chart: { renderTo: 'container3', type: 'column' }, title: { ...
chart3 = new Highcharts.Chart({ chart: { renderTo: 'container3', type: 'column' }, title: { ...
This is my first attempt at writing a Firefox add-on. I'm trying to read a text file that is contained in an Firefox Add-on I'm writing. I'm following the example from MDN let decoder = new ...
This is my first attempt at writing a Firefox add-on. I'm trying to read a text file that is contained in an Firefox Add-on I'm writing. I'm following the example from MDN let decoder = new ...