---
title: "Clear widget context using runtime JS"
slug: "clear-widget-context-using-runtime-js"
abstract: "Describes the procedure for clearing widget context using runtime JavaScript."
---
# Clear widget context using runtime JS

To clear contextual information from a widget:

1. Add a `script` block in the `head` tag above the Discover beacon.

    ```html
    <script type="module">
    // Widget context code goes here
    </script>
    ```

2. Create an `updateContext` object and set the context you want to clear to `null`. In the following code sample, the `store.id` context is cleared.

    ```javascript
    const clearContext = {
      "widget": {
        "rfkids": [ "<rfkid 1>", "<rfkid 2>", ... ]
      },
      "context": {
        "store": {
          "id": null
        }
      }
    }
    ```

    > [!tip]
    > If there are no other keys in `store`, you can set the value of `store` to `null`. In addition, if there are no other keys in `context`, you can set the value of `context` to `null`.

3. Push the `"updateContext"` action and object(s) to Discover using `rfk.push()`.

    ```javascript
    var rfk = window.rfk = window.rfk || [];
    rfk.push(["updateContext", clearContext]);
    ```

> [!important]
> If an object within `context` only contains `null` values, that object is removed from `context`.

For specific examples of how to use the `updateContext` action to clear context, refer to Examples: Clearing page and widget context.