> ## Documentation Index
> Fetch the complete documentation index at: https://webview.js.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Read and Write Cookies and Storage in a WebviewJS App

> Read, write, and delete cookies from a WebviewJS webview. Use incognito mode for ephemeral sessions or WebContext to isolate browser data across windows.

WebviewJS gives you programmatic access to the cookies and browser storage of any webview directly from Node.js. You can read cookies scoped to a URL or retrieve every cookie the webview holds, write new cookies with full attribute control, delete individual cookies or wipe all browsing data, and isolate storage between windows using incognito mode or separate `WebContext` profiles.

***

## Reading cookies

Call `webview.getCookies(url?)` to retrieve cookies. Pass a URL string to get cookies that apply to that origin, or omit the argument to get every cookie the webview has stored.

```js theme={null}
import { Application } from '@webviewjs/webview';

const app = new Application();
const win = app.createBrowserWindow();
const webview = win.createWebview({ url: 'https://example.com' });

// Cookies scoped to a URL
const cookies = webview.getCookies('https://example.com');

// Every cookie in the webview
const all = webview.getCookies();

for (const c of cookies) {
  console.log(`${c.name}=${c.value}  domain:${c.domain}`);
}

app.run();
```

***

## WebviewCookie fields

`getCookies()` returns an array of `WebviewCookie` objects. The same interface is used for `setCookie()`.

| Field      | Type                           | Description                    |
| ---------- | ------------------------------ | ------------------------------ |
| `name`     | `string`                       | Cookie name                    |
| `value`    | `string`                       | Cookie value                   |
| `domain`   | `string?`                      | Owning domain                  |
| `path`     | `string?`                      | URL path scope                 |
| `httpOnly` | `boolean?`                     | Not accessible from JavaScript |
| `secure`   | `boolean?`                     | HTTPS-only flag                |
| `sameSite` | `'strict' \| 'lax' \| 'none'?` | Cross-site policy              |

***

## Writing a cookie

Call `webview.setCookie(cookie)` with a `WebviewCookie` object to set or update a cookie. All fields except `name` and `value` are optional.

```js theme={null}
webview.setCookie({
  name:     'session',
  value:    'abc123',
  domain:   'example.com',
  path:     '/',
  httpOnly: true,
  secure:   true,
  sameSite: 'strict',
});
```

***

## Deleting cookies

Call `webview.deleteCookie(name, domain?, path?)` to remove a specific cookie. Provide `domain` and `path` for a precise match, or omit them to delete the named cookie across all domains and paths.

```js theme={null}
// Delete a specific cookie
webview.deleteCookie('session', 'example.com', '/');

// Delete by name only — removes across all domains and paths
webview.deleteCookie('session');
```

***

## Clearing all browsing data

`webview.clearAllBrowsingData()` wipes everything the webview has stored: cookies, cache, local storage, IndexedDB, and session data.

```js theme={null}
webview.clearAllBrowsingData();
```

<Warning>
  `clearAllBrowsingData()` is destructive and cannot be undone. It erases all
  cookies, cached resources, localStorage, IndexedDB databases, and session
  data for the webview. Call it only when you intentionally want to reset all
  browser state.
</Warning>

***

## Incognito mode

Pass `incognito: true` when creating a webview to start an ephemeral session. No data is written to disk, and all cookies, cache, and local storage are discarded when the webview is closed.

```js theme={null}
const webview = win.createWebview({
  url: 'https://example.com',
  incognito: true,
});
```

Incognito mode applies to the individual webview. Other webviews in the same application retain their normal persistent storage.

***

## Isolated profiles with WebContext

For scenarios where you want multiple windows with completely separate browser data — different logged-in users, isolated cache directories, or distinct session cookies — create a `WebContext` for each profile and pass it when creating the webview.

```js theme={null}
import { Application } from '@webviewjs/webview';

const app = new Application();

// Create an isolated browser data context with its own on-disk directory
const userContext = app.createWebContext({
  dataDirectory: './profiles/user1',
});

const win = app.createBrowserWindow({ title: 'User 1' });
const webview = win.createWebview({
  url: 'https://example.com',
  webContext: userContext,
});

app.run();
```

Cookies, cache, and storage stored through `webview` are isolated to `./profiles/user1` and do not bleed into other webviews or profiles. See the [WebContext API reference](/api/web-context) for additional options.

***

## Related pages

* [WebContext API reference](/api/web-context) — profile isolation, shared contexts, and automation
* [Webview API reference](/api/webview) — full cookie method signatures and `WebviewOptions`
* [Custom Protocols](/guides/custom-protocols) — serving local files without an HTTP server
