Can defold html5 game run in background?

How to make html5 always running if not focus window. Tell me if you know some way to do

Some browser policies restrict executing Javascript in background, but here’s a trick that might be helpful for you:

Do you really need to run the whole game in the background? What is your feature you would like to run in background? Isn’t it some idle income?

:white_check_mark: If so, you only need to know how much time passed between a time when window focus was lost and revoked again and then calculate how much you can change some values, when window focus is on again :wink:

Check out the window api:

If you are using Monarch (convenience library for screen management), you can use also its API instead:

Let me know if this helps you, or you need further assistance? :wink:

2 Likes

i have a socket connection and i need send to backend server a confirm message client no afk. because if it have afk overtime, backend server will kick it out. i must to do this action in game. because in game was fetched id of user account. id of user account to confirm which account will be kick when player using muntiple account on device

But if the tab with the game doesnt have focus then it is not unreasonable for the server to consider the user afk?

No bro. In my game have auto mode for player control character automatic training and farm mob. This afk is meaning is player loss connection or window game have crash, sometime in case game was closed by window task manager… back end server can automatic tracking and kick them, and other player will can see their out in game