[SOLVED] Detect user leaving the browser tab

Is there a way to detect if the user/player goes to other tab in Playcanvas?
I would need to be able to pause/unpause my game in case the browser tab loses focus.

Hi @jariwake,

You can use the browser Page Visibility API for that:

Thanks, but how to integrate that into a PlayCanvas game? Just adding that example code to a script causes error “Cannot read property ‘addEventListener’ of null”

EDIT: nevermind, found the solution here: [SOLVED] Where to put visibilitychange-function

1 Like