How Opera’s extension API threw InvalidStateError during storage access and the permissions manifest fix that restored persistent settings

One day, everything was going smoothly for Opera extension developers. Their add-ons were saving settings, reading them, and using them without a glitch. But then—bam! Suddenly, an extension that once remembered everything started forgetting everything. Settings disappeared between restarts. Developers were left scratching their heads. What happened?

TL;DR

Opera extensions started throwing InvalidStateError when trying to access storage. This broke persistent settings, making extensions forget everything. The issue was traced back to missing permissions in the manifest file. Adding the correct permission line fixed the problem. Crisis averted!

What is InvalidStateError, Anyway?

Let’s simplify it. When an extension saves data (like user settings), it uses something called storage. It’s like a digital notebook. But when Opera throws InvalidStateError, it’s basically shouting, “Hey! I have no idea where to write this down!”

This error doesn’t mean your code is totally wrong. It just means Opera’s brain wasn’t prepared to store data when the request came in. Kind of like showing up to a test without a pencil.

Why This Happened—Unexpected Changes

The issue caught many developers by surprise. Their code hadn’t changed. So why did storage access start failing?

The answer: changes within Opera’s own systems. Opera started enforcing stricter rules for extension permissions. If your extension wasn’t officially asking to use storage, it’d get the red card. No storage for you!

The Early Signs

For many, the first sign was settings disappearing. They’d restart Opera and—poof—it was like the extension had short-term memory loss. If they opened up the console, they would see something like:

Uncaught (in promise) DOMException: Failed to execute ‘setItem’ on ‘Storage’: InvalidStateError

Not very helpful, right? It doesn’t clearly say “missing permissions.” That’s what threw a lot of devs off the trail.

The Fix: Adding Permissions to the Manifest

The solution was surprisingly simple. Extensions needed to be very clear about what they wanted to access. That meant telling Opera, right in the manifest.json file: “Yes, I need to use storage!”

This was done with one small change:

"permissions": [
  "storage"
]

Once this line was added, Opera nodded in approval. “Ah! You asked nicely. Now you may store and retrieve your data.”

How It Works Behind the Scenes

The storage permission lets your extension use the chrome.storage API. Without declaring this, modern browsers like Opera don’t give your code access to it.

This is part of a larger trend: browsers are getting stricter for security and privacy reasons. They don’t want rogue extensions misusing your data. So now, even honest extensions need to be very specific in what they’ll do.

Where Most Developers Went Wrong

Many devs were using code like this for years without issue:

chrome.storage.local.set({ someKey: someValue });

But when Opera tightened permissions, this started silently failing. The runtime didn’t always throw obvious errors, and some settings still seemed to work temporarily. Which made debugging very confusing.

Let’s list the most common missteps:

  • Not including the “storage” permission in the manifest.
  • Assuming that code which worked in Chrome would work in Opera too.
  • Blaming storage quota or syntax errors instead of the manifest.

The Role of Manifest V3

This also intersects with the shift to Manifest V3. Many extensions are upgrading, as older versions may soon be deprecated.

Manifest V3 is more strict about permissions, including host permissions and features like background scripts. If your extension is set to use MV3 and lacks the right permissions, Opera puts on the handbrakes instantly.

How to Test If Storage is Working

Want to know if your extension is correctly storing data? Try this simple endpoint from your background or popup:

chrome.storage.local.get(["someKey"], function(result) {
  console.log("Value currently is " + result.someKey);
});

If this returns undefined or shows an error in the console, your permission is probably missing. Go back and double-check your manifest!

What If You Use Sync Storage?

Good question! Some developers use chrome.storage.sync to synchronize settings across devices.

To use that, you still need the same basic “storage” permission. But in heavy use, sync comes with extra things to consider, such as:

  • Rate limits—can’t store unlimited data all the time
  • Conflicts when syncing between multiple machines

For most extensions, storage.local is simpler and more reliable unless you really need synchronization across browsers.

This Isn’t Just an Opera Problem

Opera may have been the browser that made this issue obvious, but the trend is browser-wide. Firefox, Edge, even Chrome are becoming more serious about permissions and APIs in extensions.

If you add the “storage” permission now, your code is more compatible across the board. It’s like brushing your extension’s teeth—hardly exciting, but it prevents bigger pain later.

Other Permissions Worth Reviewing

While you’re fixing your manifest, check for other missing permissions. You may also need:

  • “tabs” – for accessing active browser tabs
  • “cookies” – for cookie management
  • “background” – to run persistent background scripts

Each of these should be declared if your extension uses related APIs.

A Good Manifest is Your Best Friend

Think of manifest.json as your extension’s passport. If it doesn’t clearly say what your extension needs to do, then browsers like Opera deny it access. Period.

Final Checklist

Here’s a simple list to keep your extension storage trouble-free:

  • Declare “storage” in your manifest.
  • Check for JavaScript errors in the background console.
  • Use chrome.storage.local.get() and .set() for testing.
  • Upgrade your extension to Manifest V3, if you haven’t already.
  • Review all the APIs your extension uses and declare them properly.

Conclusion

If your Opera extension suddenly forgot its settings, you’re not alone. The weird InvalidStateError was a result of missing permissions—specifically access to storage in the manifest file. Once that was added, everything went back to normal.

This hiccup taught many developers a valuable lesson: always declare what your extension needs—clearly and explicitly.

Extensions may be small, but they pack a punch. And like superheroes, they need permission before saving the world—or your preferences.

Recommended Articles

Share
Tweet
Pin
Share
Share