Storing app preferences
If you want your app to remember a selected view or table density, the DataMiner host can save that preference in the browser. The iframe cannot access localStorage directly, so the app exchanges messages with the host to save and retrieve JSON-serializable values.
Note
Storage is scoped to the app. Stored values cannot be shared across apps.
Caution
Do not store credentials or other sensitive data in app storage. App storage is intended for preferences and does not provide secure storage for secrets.
Message syntax
The app posts reads and writes to window.parent. Replies to reads arrive as window messages.
| Operation | Message |
|---|---|
| Write a value | { storage: { write: { key: string, data: unknown } } } |
| Read a value | { storage: { read: { key: string } } } |
| Read reply | { storage: { key: string, data: unknown } } |
A read reply includes the requested key. There is no delete command: writing null changes the stored value without removing the key.
Example: Remember table density
window.addEventListener("message", event => {
if (event.source !== window.parent) return;
const stored = event.data?.storage;
if (stored?.key !== "tableDensity") return;
// Default to the comfortable layout if no recognized preference is saved.
const density = stored.data === "compact" ? "compact" : "comfortable";
document.documentElement.dataset.tableDensity = density;
});
// Read the preference at startup, after registering the listener.
window.parent.postMessage({ storage: { read: { key: "tableDensity" } } }, "*");
// When the user selects the compact layout, apply and save the preference.
document.documentElement.dataset.tableDensity = "compact";
window.parent.postMessage({
storage: { write: { key: "tableDensity", data: "compact" } }
}, "*");
Error messages
Storage commands do not return structured error messages.
| What the app receives | Meaning |
|---|---|
A read reply with data: null |
The key is missing, its value is null, or browser storage is unavailable. The reply does not distinguish these cases. |
| No read reply | An invalid read command is ignored. A storage access failure or an unreadable stored value can also leave the read unanswered. |
| No write reply | Neither a successful write nor a failed write sends a reply. |