Software Development

Methods to Use Storage in Internet Extensions

Engaged on an online extension is an attention-grabbing expertise — you get to style internet whereas working with particular extension APIs. One such API is storage — the online extension taste of persistence. Let’s discover how you should utilize session and native storage inside your Manifest V3 internet extensions!

Enabling Extension Storage

The extension storage API is not accessible by default. To allow the storage API, you could cite it within the manifest.json file of your extension:

  // extra....
  "manifest_version": 3,
  "identify": "__MSG_appName__",
  "permissions": [
    // more....
  // extra....

Including storage to the permissions array, which is a prime stage manifest.json key, gives session and native storage capabilities to your extension.

Get, Set, and Take away Storage Values

Very similar to conventional localStorage and sessionStorage APIs, extension storage gives get, set, and take away operations:

// set
await identify: "David", coloration: "inexperienced" );

// get 
const  identify, coloration  = await["name", "color"]);

// take away
await away(["name", "color"]);

A number of issues to notice:

  • get requires an array argument, not a single worth like localStorage and sessionStorage
  • set must be an object format
  • take away can be an array, very similar to get
  • You need to use or relying on how
  • The entire extension storage API strategies are promise-based, with await or callback codecs

Clear All Storage

Within the occasion that you just need to clear all knowledge for native or session storage, there is a clear technique:


Utilizing clear is efficient however you may need to ensure that you do actually need to clear all the pieces — clear might grow to be a upkeep problem.

Storage is a vital a part of most internet extensions. Whereas the API is straightforward, the async format and technique names are totally different.

What's your reaction?

Leave A Reply

Your email address will not be published. Required fields are marked *