Nikola Stojaković
Nikola Stojaković

Reputation: 2305

Unexpected error occurrs when I try to acess local storage in my extension

I'm updating the extension I wrote few months ago and just when I finished I realized that local storage in loader.js (file which is loaded on each visit to the specific page) returns:

Error: "An unexpected error occurred."

It is the part where I try to load informations from the local storage:

chrome.storage.local.get('setting-one', result => {
  if (chrome.runtime.lastError) {
    throw new Error(chrome.runtime.lastError); // error is thrown
  ...

This worked without problems in the past but now it doesn't. This is the case for Firefox. On Chrome, extension doesn't work either and doesn't return any error from loader.js. I'm not sure if API has changed or some new changes were introduced regarding access to local storage. I was looking for the solution on the web but there is nothing regarding this problem.

On the page of extension I can set and get all informations from storage without any problem.

Upvotes: 0

Views: 416

Answers (1)

papo
papo

Reputation: 1959

Seems like your problem is resolved, but there is one bug in Firefox which I encountered few times. It might have been what happened to you although I can't reproduce it today for your case. I did loose some time today on a very similar situation with the same error message.

The error: Error: An unexpected error occurred is seen sometimes on Firefox, after successful call of a method,
if you also define a catch method and when you have DevTools open and turned on both Pause on exceptions and Pause on caught exceptions

Today I had this on the end of a method I used:

return browser.storage.local.set(storedObject)
    .then(() => console.log('Util_WebExt.saveToStorage(): '+valueName+' stored.'))
    .catch(e => console.error('Util_WebExt.saveToStorage(): '+valueName+' | error: '+e));

I did try it on get() as was your case, but the error did not show. Also, it does not show on storage.sync, only storage.local

On other occasions, I had the same behavior with a different case, different method. Can't remember, but there is a post on stackoverflow where it's claimed that this is a feature and not a bug. I don't see how though. It was probably misunderstood.

Upvotes: 1

Related Questions