Anti-Visibility Cloak

Force pages to always think the tab is visible/focused; optionally spoofs mouse as always "in page" and blocks exit/enter intent; shows a tiny popup when a visibility or mouse check is detected

作者
Spinfal
日安装量
2
总安装量
9
评分
0 0 0
版本
1.1
创建于
2025-08-26
更新于
2025-08-29
大小
12.3 KB
许可证
GPL-3.0-or-later
适用于
所有网站

always visible (Anti-Visibility Cloak)

this userscript forces all websites to always think the tab is visible and focused. it blocks or rewrites all known methods that pages use to detect tab visibility or focus state, and optionally notifies you when those checks happen.


features

1. overrides core visibility properties

  • document.visibilityState → always returns "visible"
  • document.hidden → always returns false
  • legacy properties like webkitVisibilityState, mozHidden, msHidden, etc. → overridden the same way
  • document.hasFocus() → always returns true

2. intercepts visibility-related events

  • blocks/manipulates visibilitychange, webkitvisibilitychange, mozvisibilitychange, msvisibilitychange
  • blocks/manipulates lifecycle events like pagehide, pageshow, freeze, resume
  • also covers focus / blur events (configurable to reduce noise)

when a site tries to attach an event listener, the script wraps the handler so it always sees the document as visible.

3. configurable popup notifications

  • a popup appears when a check or event is detected and bypassed
  • configurable in the CONFIG object:
    • properties: notify when visibility properties are read
    • hasFocusCall: notify when document.hasFocus() is called
    • addListener: notify when a site registers an event listener
    • invoke: notify when a wrapped event listener is invoked
    • suppressFocusOnEditable: prevents noisy popups when typing in inputs/textarea/contenteditable

4. popup behavior

  • small, dark box with text in bottom-right corner
  • automatically fades out after ~1.6s
  • after fade animation, it removes itself from the dom entirely (prevents clutter/overlap)

5. self-defense against scripts re-defining props

  • uses Object.defineProperty to lock down visibility state values
  • mutation observer re-applies the overrides if another script tries to reset them

6. compatibility

  • runs at document-start so it applies before most site scripts
  • works across all frames (@all-frames true)
  • no external dependencies, runs in tampermonkey/violentmonkey

use cases

  • prevent video players from auto-pausing on tab switch
    • useful for discord's quest videos visibility checks
  • stop analytics/ads from knowing if the page is backgrounded
  • testing/debugging sites that rely on visibility APIs

checking if it works

you can use these two websites to check if the userscript is working:

- https://visibility-api.netlify.app/