Device Storage (upcoming)
Available in version 1.1.72 (not yet live).
Persist key–value data on this device. Survives Desktop Agent restarts, uninstalls, and reinstalls. Stays on this device; data is never sent to ZeroWork servers.
API zw.deviceStorage.*
const credentials = {
username: await zw.deviceStorage.get("username_salesforce"),
password: await zw.deviceStorage.get("password_salesforce"),
};
await zw.deviceStorage.set("last_login_salesforce", String(Date.now()));
At a Glance
async
await zw.deviceStorage.get(key: string)
→ returns thestring
value for the key, orundefined
if not set.async
await zw.deviceStorage.set(key: string, value: string)
→ saves astring
value under the key.async
await zw.deviceStorage.remove(key: string)
→ removes the key and its value from device storage.async
await zw.deviceStorage.has(key: string)
→ returnstrue
if the key exists, otherwisefalse
.async
await zw.deviceStorage.getAll()
→ returns an object of key–value pairs{ [key: string]: string }
.
Examples
Check if value is present and set if not
if (!(await zw.deviceStorage.has("machine_id"))) {
await zw.deviceStorage.set("machine_id", "M1234");
}
Securely log in with credentials stored only locally
// @zw-run-locally
const credentials = {
username: await zw.deviceStorage.get("username_salesforce"),
password: await zw.deviceStorage.get("password_salesforce"),
};
// Get the active page and enter credentials programmatically
// Alternatively, use zw.deviceStorage.* directly in no-code blocks
const page = await zw.browserContext.getActivePage();
await page.goto("https://login.salesforce.com/");
await page.type("#username", credentials.username);
await page.type("#password", credentials.password);
Clear device storage
// Get an object mapping keys to string values
const all = await zw.deviceStorage.getAll();
await zw.log("deviceStorage keys", Object.keys(all));
const keys = Object.keys(all);
for (const key of keys) {
await zw.deviceStorage.remove(key);
}
Saving Non-String Values
Device storage only accepts strings. You can stringify on write and parse on read if you want to work with other types.
// Save an object (stringify on write)
const creds = { username: "alice", token: "abc123" };
await zw.deviceStorage.set("sf_creds", JSON.stringify(creds));
// Read it back (parse on read)
const raw = await zw.deviceStorage.get("sf_creds");
const parsed = raw ? JSON.parse(raw) : null;
Notes
Size limits. Total device storage is limited to ~3,000,000 characters. Writes that would exceed the total limit will throw an error.
Always use
await
. All methods inzw.deviceStorage.*
are async, whether the code runs locally or in the browser.// 🚫 Won't work const someValue = zw.deviceStorage.get("someKey"); // missing await // ✅ Works const someValue = await zw.deviceStorage.get("someKey");
Last updated
Was this helpful?