Hi everyone, I'm trying to access local storage fr...
# javascript
Hi everyone, I'm trying to access local storage from web-extension:
Copy code
                delegate = js("self.chrome.storage.local") as? Storage ?: js("self.localStorage") as? Storage ?: error("Could not create chrome.storage.local"),
but so far I get
ERROR ReferenceError: Storage is not defined
, any recommendation what I might be doing wrong?
local storage can be accessed with
Copy code
external val localStorage: Storage
Try taking a look at the Kotlin Wrappers project - it provides common implementations, including
https://github.com/JetBrains/kotlin-wrappers/blob/b3386a80419d76e48f1a35e5ff7afad746e91faf/kotlin-browser/src/jsMain/generated/web/storage/localStorage.val.kt#L3 I can't see an equivalent for
, but you can probably use Kotlin Wrappers for inspiration
do you know what this code is generated from? I.e. the interface for chrome.storage.local is more complex, can't work it out to fit. Another way to do it is just rely on js() dynamic code usage
ot, I think I made some progress with this interface:
Copy code
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>