storage.set
Writes one value to your app's own storage on the phone.
Writes a text value by key. A write that would pass the app's quota is refused with ok: false, never an error.
| Property | Value |
|---|---|
| Scope | None (open method) |
| Who can use it | Any developer |
| Status | Available |
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
key | string | Yes | A key is 1 to 128 characters: letters, digits and . _ : -. |
value | string | Yes | Text up to 65,536 characters. The whole app may keep about 256 KB in total. |
Result
| Field | Type | Description |
|---|---|---|
ok | boolean | false with reason: "quota" when the write did not fit. |
reason | string | Present only with ok: false. |
Errors
| Code | When |
|---|---|
-32602 | A parameter is missing, has the wrong type or is over its limit. |
4200 | Storage cannot be written: there is no signed-in account, or the device store failed. |
4290 | More than 30 requests in 10 seconds. |
See Error Codes for every code and how they reach your page.
Example
const r = await window.aksa.request({
method: "storage.set",
params: { key: "state", value: JSON.stringify(state) },
});
if (!r.ok) showQuotaMessage();With AksaMini
If your page embeds aksa-mini.js, use its wrapper:
await AksaMini.store.setJSON("state", state);Notes
- Check
ok. A full quota is a normal result, so handle it instead of assuming the save worked. - Use this instead of
localStorage: served apps run in a sandbox where direct DOM storage may not work. - With no signed-in account the host answers
4200for a write.
Used By
Ready To Build Or Ship?
Check your files, preview on an iPhone frame, and submit in the Developer Studio.