Safari web extension - background script - sessionStorage

I converted an extension from Chrome to Safari using:

xcrun safari-web-extension-converter

All works except for one thing: when trying to access the localStorage or sessionStorage from background script I get:

SecurityError: the operation is insecure.

It works in all other browsers (chrome, firefox, edge) - but not here. I hope that the solution is to turn on some flag in the xcode build settings and not to try and implement some native swift code - which I (and many other developers) will not do.

Any solution?

Where are you trying to store session data? You mentioned your background script, but it is unclear if you are trying to set session data for the background page, popup, extension page or on a webpage via content script.

I said - background script. In the manifest file of browsers extension (chrome, firefox, edge) you have the manifest.json in which you define what is the background script. After I converted the extension to a Safari extension, Any access from the background script to window.sessionStorage was denied, which is extremely weird. Should I configure anything in the Xcode project after the conversion to solve that problem? Is it a Safari converter bug? Anything else?

Anybody home?

I'm suggesting to switch to the browser.storage / chrome.storage API. In some other browsers / future browsers support for sessionStorage and localStorage is dropped for extensions. See: https://groups.google.com/a/chromium.org/g/chromium-extensions/c/6qiMo0P-XS4

@nbe I never got notified you replied.

I am able to set, get and remove session and local storage from my background page/script without issue. I am not using the safari converter however, so perhaps it's an issue with that or how you are going about setting/getting. That being said the person who replied has good advice, I'd do what he says.

Does this reproduce in a basic sample extension? I would expect localStorage to work for you.

If you could file feedback at https://feedbackassistant.apple.com with a sample extension that shows this issue, that would be great.

Thanks!

Hi @bweinstein, for me accessing localStorage and sessionStorage in a background script of Safari extension doesn't work. I can't provide a sample extension now. @bweinstein, can you first confirm that accessing sessionStorage from a background script works for you without SecurityError?

Safari web extension - background script - sessionStorage
 
 
Q