---
title: "clearCookies() | Grafana k6 documentation"
description: "Clears context cookies."
---

> For a curated documentation index, see [llms.txt](/llms.txt). For the complete documentation index, see [llms-full.txt](/llms-full.txt).

# clearCookies()

Clears the [browser context](/docs/k6/next/javascript-api/k6-browser/browsercontext/)’s cookies.

### Returns

Expand table

| Type            | Description                                                                                                                                     |
|-----------------|-------------------------------------------------------------------------------------------------------------------------------------------------|
| `Promise<void>` | A Promise that fulfills when the cookies have been cleared from the [browser context](/docs/k6/next/javascript-api/k6-browser/browsercontext/). |

### Example

JavaScript ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```javascript
import { browser } from 'k6/browser';

export const options = {
  scenarios: {
    browser: {
      executor: 'shared-iterations',
      options: {
        browser: {
          type: 'chromium',
        },
      },
    },
  },
};

export default async function () {
  const context = await browser.newContext();
  const page = await context.newPage();

  await page.goto('https://httpbin.org/cookies/set?testcookie=testcookievalue');
  let cookies = await context.cookies();
  console.log(cookies.length); // prints: 1

  await context.clearCookies();
  cookies = await context.cookies();
  console.log(cookies.length); // prints: 0
}
```
