The popup window will be closed when the user leaves it.

Not a perfect, but you can refer to https://github.com/ripper2hl/whitenoisefy.