angry kiwi
angry kiwi

Reputation: 11445

Chrome extension error - Unexpected illegal token

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

Answers (1)

Ivo Wetzel
Ivo Wetzel

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

Related Questions