# getCookies

Retrieve a [cookie](https://w3c.github.io/webdriver/webdriver-spec.html#cookies) visible to the current page. You can query a specific cookie by providing the cookie name or retrieve all.

## Usage[​](#usage "Direct link to Usage")

```
await browser.getCookies(filter, sourceOrigin)
```

## Parameters[​](#parameters "Direct link to Parameters")

| Name           | Type                         | Details                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| -------------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `filter`       | `remote.StorageCookieFilter` | an object that allows to filter for cookies with specific attributes                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `sourceOrigin` | `string, null`               | an optional source origin to fetch cookies for, if not provided it will default to the current page's origin, if explicitly set to null it will fetch cookies without a partition (only supported in BiDi). With `wdio:experimentalBiDiCommands` and in a parallel test, the commands use the cookies of the window: without `sourceOrigin`, the cookies that the page sees (domain and path) or, with a `domain` in the filter, the cookies of that domain, with `sourceOrigin`, the WebDriver BiDi storage partition of that origin, and with null, all cookies of the window |

## Example[​](#example "Direct link to Example")

getCookies.js

```
it('should return a cookie for me', async () => {

    await browser.setCookies([

        {name: 'test', value: '123'},

        {name: 'test2', value: '456'}

    ])

    const testCookie = await browser.getCookies({ name: 'test' })

    console.log(testCookie); // outputs: [{ name: 'test', value: '123' }]



    const allCookies = await browser.getCookies()

    console.log(allCookies);

    // outputs:

    // [

    //    { name: 'test', value: '123' },

    //    { name: 'test2', value: '456' }

    // ]



    // filter cookies by domain

    const stagingCookies = await browser.getCookies({

        domain: 'staging.myapplication.com'

    })

})
```

## Returns[​](#returns "Direct link to Returns")

* **\<Cookie\[]>** **`return`:** requested cookies
