Disable Tab Switch Detection

Prevent websites from detecting tab switches

  1. // ==UserScript==
  2. // @name Disable Tab Switch Detection
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.5
  5. // @description Prevent websites from detecting tab switches
  6. // @author DharmTej
  7. // @match *://*/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. // Caution: Might affect other websites. Make sure to disable it when not needed.
  15.  
  16. Object.defineProperty(document, "hidden", {
  17. get: function() { return false; },
  18. configurable: true
  19. });
  20.  
  21. Object.defineProperty(document, "visibilityState", {
  22. get: function() { return "visible"; },
  23. configurable: true
  24. });
  25.  
  26. document.addEventListener("visibilitychange", function(event) {
  27. event.stopImmediatePropagation();
  28. console.log('Tab switch detection blocked');
  29. }, true);
  30. })();