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
await zw.deviceStorage.get(key)
→ returns thestring
value for the key, orundefined
if not setawait zw.deviceStorage.set(key, value)
→ saves astring
value under the keyawait zw.deviceStorage.remove(key)
→ removes the key and its value from device storageawait zw.deviceStorage.has(key)
→ returnstrue
if the key exists, otherwisefalse
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");
}
// @zw-run-locally
// Securely log in with credentials stored only 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);
// Returns an object mapping keys to string values
const all = await zw.deviceStorage.getAll();
await zw.log("deviceStorage keys", Object.keys(all));
// Clear the whole device storage
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 save 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
Total device storage is limited to ~2,000,000 characters. Writes that would exceed the total limit will throw.
All methods in
zw.deviceStorage.*
are async, whether the code runs locally or in the browser. Always useawait
.// 🚫 Won't work const someValue = zw.deviceStorage.get("someKey"); // missing await // ✅ Works const someValue = await zw.deviceStorage.get("someKey");
Last updated
Was this helpful?