state:State = new Proxy(overlay, {/** Give defaults if overlay doesn't have the key */get(target, property) {if (notBackground())throw new Error("State object must be accessed with getAsync in content",)if (property in target) {return target[property]} else {return defaults[property]}},set(target, property: keyof State, value) {logger.debug("State changed!", property, value)if (notBackground()) {const inIncognitoContext = browser.extension.inIncognitoContextbrowser.runtime.sendMessage({type: "state",command: "stateUpdate",args: { property, value, inIncognitoContext },})return true}// Do we need a global storage lock?target[property] = value// Persist "sets" to storage in the background for some keysif (PERSISTENT_KEYS.includes(property)) {// Ensure we don't accidentally store anything sensitiveif (browser.extension.inIncognitoContext) {console.error("Attempted to write to storage in private window.",)return false}browser.storage.local.set({state: R.pick(PERSISTENT_KEYS, target),} as any)}return true},})