The My Opera forums have been replaced with forums.opera.com. Please head over there to discuss Opera's products and features

See the new Forums

Need help with sessionStorage and localStorage

Forums » General Opera topics » Opera extensions

You need to be logged in to post in the forums. If you do not have an account, please sign up first.

Go to last post

23. September 2011, 07:36:06

CrudOMatic

Posts: 27

Need help with sessionStorage and localStorage

How do I even get started using session/local storage in an opera extension? I'm more interested in session storage, as I want my extension to keep a session-only history (basically the storage is GONE after opera is shut down and relaunched)

Do HTML5 session storage tutorials work here?

26. September 2011, 13:51:33

spadija

Posts: 1643

sessionStorage, localStorage, and Opera's two special storage objects, scriptStorage and widget.preferences are all HTML5 storage objects, so if you've read any good tutorial on that, you already know how they work. Just be careful of the different contexts they apply to:

                              in background script             in injected script
sessionStorage           The background script only        The tab the script is on
localStorage             The background script only        The web page the script is on
scriptStorage            (doesn't exist)                   All instances of the injected script
widget.preferences       Shared between background script and injected script (buggy on private tabs)


I haven't tried sessionStorage on the background script, but I assume it will be cleared when you disable the extension or close Opera. If you use something other than widget.preferences though, you'll have to send messages back and forth, since widget.preferences is the only one that is shared between the background script and injected script.

27. September 2011, 03:01:01

Thank you for sharing this info. There is one more possible context: popup window. Do you know how storage will work in popup context?

One more possibility to have session storage in background process is to store data in object. Functionality is almost the same as in sessionStorage, and data will be reset when Opera is closed.

27. September 2011, 06:49:45

spadija

Posts: 1643

I'm not entirely sure about this, but I believe localStorage is shared between the background script and popup, no idea about sessionStorage, scriptStorage doesn't exist there, and widget.preferences is shared in all extension contexts.

Forums » General Opera topics » Opera extensions