WebExtensions: Content script accessing storage.local

Hi,

Trying to figure out a way to handle settings in the extension.

I assume chrome.storage.local is the way to do it, yet it is not available to the content script. Is this correct?

To side-step this, I send a message to background script (chrome.runtime.sendMessage()), where it is possible to call chrome.storage.local.get() for the specified key. Yet it seems that handling of “return true” is not properly implemented (yet? https://bugzilla.mozilla.org/show_bug.cgi?id=1202481 mentions it, but it seems stuck for over a week now), so I cannot call sendResponse() from inside the .get() callback.

Please let me know if there is a working way to get keys from local storage to content script, or if I just need to wait till this part of the functionality is complete.

Hmmm…

Same obstacle with making AJAX calls—the site I need to use the extension on (GitHub) doesn’t allow scripts to load data from outside sources, yet a call from background script works (which is great!). But I can’t pass the response to that call back to content script, since sendResponse() doesn’t work from an asynchronous callback.

OK, found one possible workaround—in the callback in the background script, instead of calling sendResponse() (which doesn’t work), I can send a message to the tab that called bg.js in the first place.

Sooo… it is possible to implement, but takes “Callback Hell” to a new level. I really hope there is a better solution, or that handling of “return true” will be implemented soon.

Theres no pref system?

That’s how addons do it, we write a preference to about:config and delete it on uninstall.

stoarge is mostly for actualy storage of data/files etc

If there is a preference API with WebExtensions, I would definitely like to know about it.

At the moment no access to Fx pref system. And for content scripts is access to local storage planned but not yet available.

1 Like

I suspect we’ll be implementing the options_page API at some point in the future, but I don’t think it’s there yet.

1 Like