0

I am in the process of translating my Chrome extension into a Firefox extension. I am having a problem though.

My extension requires stored data for the extension to be loaded in the content script as well as in the popup page. I have no problem with this in my Chrome extension. I just use chrome.storage to pass and retrieve storage and I can use that both in my content and popup scripts with ease.

With Firefox, I'm having a having a hard time figuring out exactly what I have to do different. I got that I can't use chrome.storage and rather use the

const storage = require("sdk/simple-storage").storage;

thing, but I need to use this in both the content script and the script for the popup page. I researched and found I can't use the require function more than once, so my question is, would I be able to share the variable between the popup script and the content script? I need the storage from both sides and there isn't any other way I can see to make the extension work.

Thanks.

1 Answer 1

4

You use message-passing to have the content script the main addon communicate with each other.

Two possible approaches:

  • send down the data in advance if it's not too large / doesn't affect too many tabs and also push down updates as they happen. this provides superior read latency at the potential cost of increased memory footprint and increased cost of writes.
  • request individual data items on demand. this is better for frequently-written or large items of data but comes at the cost of higher latency per request.

You also might want to look at webextensions. storage in content is not yet supported there either, but it probably will be in the future.

Sign up to request clarification or add additional context in comments.

1 Comment

The only api my extension uses is storage :( but if what you're saying means I can pass a variable with all the data I need from the popup script to the content script then that's all I need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.