We are working on a web app in which we need to fire an event whenever the user closes the laptop lid or locked the screen, for this we are using VisibilityAPI , now this API listen when the window hides, we need to exclude the minimize and tabl switch event from this, can you please let us know that how can we exclude the minimize and tab switch event and only listen to the window lock event?
There are several points you need to be aware of.
-
Not all “closing laptop lid” events fire
visibilitychange
events, it depends on system configuration within which “whether to keep screen on when closing laptop lid” is set to false. -
visibilitychange
events are fired only when the interested tab is visible on screen, which means besides ①"minimize", ②"tab switch" and ③"locking screen"events, ④"virtual desktop switch" and ⑤"other windows dragged to entirely cover the interested tab" events also exist. -
you can never distinguish between ③, ④, ⑤.
-
you can recognize â‘ when using extension to get the active window or the interested window is the active window, of which
innerWidth
andouterWidth
are updated andouterWidth - innerWidth < 0
is true. -
you can recognize ② only when using extension to get the active window and judge whether the active window is equal to the interested window.
Using statistics and smart algorithm may be of some help and not mention above.