Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught TypeError: Cannot read property 'local' of undefined in chrome extension

I have written a Chrome extension. I cannot use localStorage.setItem and localStorage.getItem for storing and retrieving because background and browser action runs in different environment [as seen here].

So I decided to use the Chrome storage API:

var storage = chrome.storage.local;
var myTestVar = 'somevar';
var obj = {};
obj[myTestVar] = $("#somevar").val();
storage.set(obj);

which produced the following error:

Uncaught TypeError: Cannot read property 'local' of undefined

What am I doing wrong?

like image 479
Milind Anantwar Avatar asked Feb 27 '13 13:02

Milind Anantwar


1 Answers

You'll get this error if you try running your app as a simple HTML page opening the HTML file in Chrome.

Add the app in Chrome properly (as an Extension) then run it.

like image 77
Vitalicus Avatar answered Oct 10 '22 12:10

Vitalicus