ejfrancis
ejfrancis

Reputation: 3045

Chrome Extensions storage.local.set "Cannot read property 'name' of undefined"

I'm using Chrome's local storage for a browser extensions. When attempting to store an object, I randomly get an error sometimes of "Cannot read property 'name' of undefined", breaking at the line where I call chrome.storage.local.set() like so:

chrome.storage.local.set({"channels":ContentApp.channels}, function(data){
    console.log(data)
});

The error never happens the first time I store the object, only after that initial storage. Anyone know what's causing this? I don't see a property 'name' being accessed on that line, or in any of the functions in the stack trace, so I don't get where the 'name' property is coming from.

Upvotes: 0

Views: 1636

Answers (1)

ejfrancis
ejfrancis

Reputation: 3045

The solution was simple, but I'm posting it so anyone who faces the same confusion sees this.

The error was being thrown at the line of

chrome.storage.local.set()

but in reality it was happening inside a method that was being called within the callback. The call stack of the error didn't bubble out of the callback of .set(), so it was reported at the line of the .set() call.

Upvotes: 1

Related Questions