Is an element still on the view-port if the user switches tabs from it?

I’m trying to detect tab-switching and wondering if it can be done using $w(“Page”).OnViewportLeave(). Any other ideas to detect tab-switching are also welcome.