why js function works only when I run it with the debugger?

I have a javascript code and in this code I send an axios request to get the user whose password he entered belongs to him.
the problem is:
When I debug the code in the browser debug tool(f12), the code works fine, but if I don’t debug the code, the user login page refreshes again and again and there is no transition to the requested page.
what could be the problem? After all, it seems that the code is correct because when there is debugging it works…

The interesting thing is that in the first few runs of the function, the function worked fine even without the debugger, but only after a few times of running the function, the problems started as I mentioned above.

I would appreciate your help, thanks

**here is the js code:
**

function getPsd() {
    sessionStorage.login = null;
    var psd = document.getElementById("password").value;
    var fullPath = 'https://localhost:44371/api/Users/Get/?psd=';
    return axios.get(fullPath + psd).then(
        (response) => {
            var result = response.data;
            if (result != null) {
                sessionStorage.login = JSON.stringify(result);
                window.location.href = '../HomePage/HomelPage.html'
            }
            return result;
        }).catch((error) => {
            alert("erorr details")
            return null;
        });
}

**html code:
**

<body dir="rtl">
    <div class="login-container">
        <section class="login" id="login">
            <header>
               
                <h4>user login</h4>
            </header>
            <form class="login-form">
                <input type="text" id="userName" class="login-input" placeholder="User" required autofocus />
                <input type="password" id="password" class="login-input" placeholder="Password" required />
                <div class="submit-container">
                    <button onclick="getPsd()" class="login-button">היכנס</button>
                </div>
            </form>
        </section>
    </div>
</body>

I tried to search for any relevant solution but i didn’t find nothing…