Closed ar-g closed 1 year ago
After more investigation it looks like there's needs to be implemented fallback in order to run on the WebExtension. More info here: https://stackoverflow.com/questions/40887635/access-localstorage-from-service-worker and here https://stackoverflow.com/questions/70704283/how-to-use-localstorage-or-an-alternative-in-manifest-v3
So far I've tried this with no luck
StorageSettings(
delegate = js("self.chrome.storage.local") as? Storage ?: js("self.localStorage") as? Storage ?: error("Could not create chrome.storage.local"),
)
made some progress with this interface:
public external interface ChromeStorage {
fun set(items: dynamic): Promise<Unit>
fun get(key: String): Promise<dynamic>
fun remove(key: String): Promise<Unit>
fun clear(): Promise<Unit>
}
which is doesn't really fit synchronous interface of Settings, so I'd probably have to throw away the library and roll different implementations with suspend as part of the interface
You might be able to get it working with the SuspendSettings
interface in the coroutines module.
@ar-g Do you still need help here? I'm inclined to close this unless you think there's something the library could add that would help your use-case.
Hey wanted to confirm if we tend to use the SuspendSettings, the library would work even with web worker ?
@aggarwalpulkit596 The library is not doing anything explicitly to help you with web worker. But if you have a Promise
-based interface like the ChromeStorage
defined above, you should be able to convert the promises to suspend functions and use that to write a custom implementation of SuspendSettings
.
I'm currently getting:
When trying to initialise Settings in web-extension:
Is there a specific place I should be trying to do it?