Closing window not working proberly

Bildschirmfoto 2021-01-21 um 18.04.00

The workflow and the script take the source code of the webpage. After processing I want the window to be closed. This works fine if I run the macro manually. If it runs at the scheduled times and the screen is locked, the window is not closed.

Any idea why?