There are several points you need to be aware of.
-
Not all “closing laptop lid” events fire
visibilitychangeevents, it depends on system configuration within which “whether to keep screen on when closing laptop lid” is set to false. -
visibilitychangeevents 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
innerWidthandouterWidthare updated andouterWidth - innerWidth < 0is 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.