31

I am getting this exception in my background.html page. I don't know what this exception says. Can anyone explain this exception and also tell me how to resolve this exception.

The exception details are

Unchecked runtime.lastError while running storage.set: QUOTA_BYTES_PER_ITEM quota exceeded

Thank you.

Java4you
  • 576
  • 2
  • 10
  • 20
  • 3
    Even without looking at documentation, I'd guess "`storage ... BYTES_PER_ITEM quota exceeded`" is saying you're trying to store too large of an object under a single key. – Teepeemm Oct 08 '15 at 14:06
  • 2
    Thank you for your response. I solved my issue by using chrome.storage.local 5,242,880 QUOTA_BYTES. This solved my problem. The maximum amount (in bytes) of data that can be stored in local storage, as measured by the JSON stringification of every value plus every key's length. This value will be ignored if the extension has the unlimitedStorage permission – Java4you Oct 19 '15 at 06:12

2 Answers2

53

This error comes when you use chrome.storage.sync.set...to set the data greater than 8,192 bytes for a single item as chrome.storage.sync.set allows 8,192 QUOTA_BYTES_PER_ITEM.

Use chrome.storage.local.set, to save the large data...instead of chrome.storage.sync.set.
As chrome.storage.local.set can contains 5242880 :QUOTA_BYTES.

See https://developer.chrome.com/extensions/storage

Also, you can get the alert if still want to use chrome.storage.sync.set using below code:

chrome.storage.sync.set(function() {  
   var error = chrome.runtime.lastError;  
   if (error) {  
      alert(error);  
   }  
});   

If you are getting same warning with chrome.storage.local too, then

Reason: The data you are trying to store is greater than the allowed storage with local i.e. 5242880 QUOTA_BYTES.
Solution: You can set the permission as unlimitedStorage in manifest.json file.

  "permissions": [   
    .....  
    "unlimitedStorage",  
    .....  
   ],

For more regarding permission
1) https://developer.chrome.com/extensions/storage#property-managed
2) https://developer.chrome.com/extensions/permission_warnings#nowarning

Vishal Kumar
  • 1,290
  • 14
  • 15
4

As outlined by wOxxOm in his comment above, the answer is covered in the chrome.storage documentation.

Moreover, it's always a good practice to implement error handling and check for runtime.lastError. If everything is all right, it will be undefined. If there is a problem, it will be non-empty, and chrome.runtime.lastError.message will explain what's wrong.

Chrome added checks that chrome.runtime.lastError is actually checked (evaluated). If not, it considers this to be an unhandled exception, and throws this error.

Bruno Peres
  • 2,980
  • 1
  • 21
  • 19
Marcob14
  • 141
  • 5