> For the complete documentation index, see [llms.txt](https://docs.zerowork.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zerowork.io/zw.-api/device-storage.md). Agents can also search and read this documentation through its [MCP server](https://docs.zerowork.io/~gitbook/mcp).

# Device Storage

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.*`

```js
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

* <mark style="color:$info;">async</mark>\
  `await zw.deviceStorage.get(key: string)`\
  → returns the `string` value for the key, or `undefined` if not set.
* <mark style="color:$info;">async</mark>\
  `await zw.deviceStorage.set(key: string, value: string)`\
  → saves a `string` value under the key.
* <mark style="color:$info;">async</mark>\
  `await zw.deviceStorage.remove(key: string)`\
  → removes the key and its value from device storage.
* <mark style="color:$info;">async</mark>\
  `await zw.deviceStorage.has(key: string)`\
  → returns `true` if the key exists, otherwise `false`.
* <mark style="color:$info;">async</mark>\
  `await zw.deviceStorage.getAll()`\
  → returns an object of key–value pairs `{ [key: string]: string }`.

***

#### **Examples**

**Check if value is present and set if not**

```typescript
if (!(await zw.deviceStorage.has("machine_id"))) {
  await zw.deviceStorage.set("machine_id", "M1234");
}
```

**Securely log in with credentials stored only locally**

```js
// @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
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);
```

**Use device storage in a no-code building block**

`zw.deviceStorage.*` also works directly in the inputs of no-code building blocks.

```js
${await zw.deviceStorage.get("downloads_folder")}
```

{% hint style="warning" %}
⚠️ Avoid using `zw.deviceStorage.get()` to read *secrets* in no-code building blocks. Many building blocks auto-log values, and those logs are saved to TaskBot run reports. Only the [Write JavaScript](https://docs.zerowork.io/building-blocks/external-and-integrations/write-javascript.md) building block is guaranteed not to log values on its own.
{% endhint %}

**Clear device storage**

```js
// 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.

```js
// Save an object (stringify on write)
const runMeta = {
  machineId: "M1234",
  lastRunAt: Date.now(),
  lastProcessedInvoiceId: "INV-2026-00127",
};
await zw.deviceStorage.set("billing_bot_state", JSON.stringify(runMeta));

// Read it back (parse on read)
const raw = await zw.deviceStorage.get("billing_bot_state");
const parsed = raw ? JSON.parse(raw) : null;
```

***

#### **Adding Secrets**

For passwords, API tokens, and other sensitive values, add them in the Desktop Agent UI instead of saving them as plain text in the **Write JavaScript** building block using `zw.deviceStorage.set()`. (Reading a value with `zw.deviceStorage.get()` is safe.) Here's how: [Device Storage](https://docs.zerowork.io/device-storage/device-storage.md).

***

#### **Logging Secrets**

If you need to log sensitive values (like passwords or API tokens), use `zw.logTemp()` instead of `zw.log()`. `zw.logTemp()` shows the value in the live run logs, but it is **not** saved to TaskBot run reports.

```javascript
const secret = await zw.deviceStorage.get("some_secret");

// ✅ Good: Visible in live logs only (not saved to run reports)
await zw.logTemp(secret);

// 🚫 Avoid: Saved to TaskBot run reports
await zw.log(secret);
```

***

#### Notes

* **Size limits.**\
  Total device storage is limited to **\~3,000,000 characters**. Writes that would exceed the total limit will throw an error. Keys can be up to 250 characters long.
* **Always use `await`.**\
  All methods in `zw.deviceStorage.*` are async, whether the code runs locally or in the browser.

  ```js
  // 🚫 Won't work
  const someValue = zw.deviceStorage.get("someKey"); // missing await

  // ✅ Works
  const someValue = await zw.deviceStorage.get("someKey");
  ```
