12345678export type StorageHardening = {9 localHardened: boolean;10 sessionHardened: boolean;11 sessionEscrowAvailable: boolean;12};1314type AccessLevelArea = {15 setAccessLevel?: (options: { accessLevel: "TRUSTED_CONTEXTS" }) => Promise<void>;16};1718async function setTrustedContexts(area: unknown): Promise<boolean> {19 const typed = area as AccessLevelArea | undefined;20 if (typeof typed?.setAccessLevel !== "function") return false;21 try {22 await typed.setAccessLevel({ accessLevel: "TRUSTED_CONTEXTS" });23 return true;24 } catch {25 26 27 return false;28 }29}3031export async function hardenExtensionStorage(): Promise<StorageHardening> {32 const localHardened = await setTrustedContexts(chrome.storage?.local);33 const session = chrome.storage?.session;34 35 36 const sessionHardened = session ? await setTrustedContexts(session) : false;37 return { localHardened, sessionHardened, sessionEscrowAvailable: sessionHardened };38}