Shutting down server when closing browser tab

hello all,
I have created an application with dash. I use cx_Freeze and “python bdist_msi” to have an installable application.
See this post: Convert Dash to executable file (.exe) - #3 by MGBpy
This all works so far.
When I made some changes and created a new .msi file I wanted to install it. I did not uninstall the older version.
A new installation was not possible because my previous app was still running in the background.

The problem is that the server does not stop when I close the browser window.
I have tried several things to stop the server, e.g. with an additional javascript file with windwo.addEventListerner …
Unfortunately nothing really worked.

Does anyone have an idea how to solve this problem?