Reputation: 11445
I have this particular line of code
var o = JSON.parse(localStorage['options']);
localStorage['options'] is an object:
{"ads":true,"chat":true,"footer":true,"invite":true,"web":true,"contact":true,"window":true,"icon":t rue,"row":true,"message":true}
If I use this code in option.html, nothing wrong will happen. But in background.html, I get the error "unexpected illegal token".
how can I stop this?
Upvotes: 0
Views: 970
Reputation: 46745
I suspect that you set the value on the browser
site, not on the background
site.
Both pages have a different window
object and therefore a different localStorage
so what happens is that you background page tries to read a value that wasn't set.
Example:
> localStorage['foo']
undefined
> JSON.parse(undefined)
SyntaxError: Unexpected token ILLEGAL
To fix it, you need to set the localStorage
data in the background page.
Upvotes: 2