Handle closing the tab in HTML5 Export

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Cherep

Hi,

when playing a game in HTML5 Export, I’d like the game to first close a connection to a database before exiting if you’re closing the tab in your browser (or just do anything, really - but I would like to call some functions before immediately quitting into the void).
Is there any way to handle such a request? Because I don’t think that the standard windows notification-handling helps me out here, and I’m not sure if a custom HTML page would do it.

It’s possible that quitting on an HTML5 export is handled differently than on other platforms. I couldn’t find anything about this so it may be helpful to request documentation about it by opening an issue on GitHub.

exuin | 2021-05-15 18:21

:bust_in_silhouette: Reply From: Calinou

Godot currently doesn’t have a built-in way to add an onbeforeunload handler, but this can likely be added yourself by calling JavaScript code from GDScript.