# Create Auto Hide Feature

**URL:** <https://community.elfsight.com/t/create-auto-hide-feature/93061>\
**Category:** AI Chatbot\
**Tags:** Gathering-Feedback\
**Created:** [January 7, 2025, 7:18am UTC](https://community.elfsight.com/t/create-auto-hide-feature/93061 "2025-01-07T07:18:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![backhome84](https://sea2.discourse-cdn.com/flex020/user_avatar/community.elfsight.com/backhome84/32/49202_2.png) [@backhome84](https://community.elfsight.com/u/backhome84)\
**Post date:** [January 7, 2025, 7:18am UTC](https://community.elfsight.com/t/create-auto-hide-feature/93061/1 "2025-01-07T07:18:47Z")

</div>

Hi Max, it will be nice if the AI chat has an autohide feature to make the chat window disapear after specific time if the user did not engage in a conversation with the chat bot

---

<div class="post-metadata">

**Author:** ![Max](https://sea2.discourse-cdn.com/flex020/user_avatar/community.elfsight.com/max/32/710_2.png) [@Max](https://community.elfsight.com/u/Max)\
**Post date:** [January 10, 2025, 3:32pm UTC](https://community.elfsight.com/t/create-auto-hide-feature/93061/2 "2025-01-10T15:32:01Z")

</div>

Cool idea, thanks for sharing @backhome84 👍

---

<div class="post-metadata">

**Author:** ![Max](https://sea2.discourse-cdn.com/flex020/user_avatar/community.elfsight.com/max/32/710_2.png) [@Max](https://community.elfsight.com/u/Max)\
**Post date:** [January 14, 2025, 1:45pm UTC](https://community.elfsight.com/t/create-auto-hide-feature/93061/3 "2025-01-14T13:45:12Z")

</div>

Hi there, @backhome84 👋

Here is a solution from our dev team that should be added to the Custom JS field on the General tab of your widget’s settings:

```auto
const TIMEOUT = 30;

function waitForElement(selector, root = document) {
    return new Promise((res) => {
        let i = 0;

        function check() {
            const component = root.querySelector(selector);

            if (component) {
                res(component);
            } else if (i !== 50) {
                setTimeout(check, 100);
                i++;
            }
        }

        check();
    });
}

waitForElement("[class*='eapps-ai-chatbot'] button").then((bubble) => {
    const portal = bubble.parentNode.parentNode;
    const closeChat = () => {
        const window = portal.querySelector("[class*='window-transition__Container-sc']");
        if (window) {
            bubble?.click();
        }
    };

    let closeChatInterval = setInterval(closeChat, TIMEOUT * 1000);
    const resetInterval = () => {
        clearInterval(closeChatInterval);
        closeChatInterval = setInterval(closeChat, TIMEOUT * 1000);
    };

    document.addEventListener("visibilitychange", resetInterval);
    document.addEventListener("click", ({ target }) => {
        if (target.closest("[class*='window-transition__Container-sc']")) {
            resetInterval();
        }
    });
    document.addEventListener("keydown", ({ target }) => {
        if (target.closest("#interactionInput")) {
            resetInterval();
        }
    });
});

```

  

In the 1st line you should set the period of inactivity (in secs), after which the chat will be closed 🙂
