@@ -78,32 +78,56 @@ object FingerprintScriptGenerator {
7878 if (window.__feather_bg_play_active) return;
7979 window.__feather_bg_play_active = true;
8080
81- // 1. Override Page Visibility API so media sites always consider the tab active
81+ // 1. Override Page Visibility API on both document instance and Document.prototype
8282 try {
83- Object.defineProperty(document, 'hidden', { get: function() { return false; }, configurable: true });
84- Object.defineProperty(document, 'visibilityState', { get: function() { return 'visible'; }, configurable: true });
85- Object.defineProperty(document, 'webkitHidden', { get: function() { return false; }, configurable: true });
86- Object.defineProperty(document, 'webkitVisibilityState', { get: function() { return 'visible'; }, configurable: true });
83+ const defineProp = function(obj, prop, value) {
84+ try {
85+ Object.defineProperty(obj, prop, {
86+ get: function() { return value; },
87+ set: function() {},
88+ configurable: true,
89+ enumerable: true
90+ });
91+ } catch(e) {}
92+ };
93+
94+ defineProp(document, 'hidden', false);
95+ defineProp(document, 'visibilityState', 'visible');
96+ defineProp(document, 'webkitHidden', false);
97+ defineProp(document, 'webkitVisibilityState', 'visible');
98+ defineProp(Document.prototype, 'hidden', false);
99+ defineProp(Document.prototype, 'visibilityState', 'visible');
100+ defineProp(Document.prototype, 'webkitHidden', false);
101+ defineProp(Document.prototype, 'webkitVisibilityState', 'visible');
102+
87103 document.hasFocus = function() { return true; };
104+ Document.prototype.hasFocus = function() { return true; };
105+
106+ // Override property event handlers
107+ defineProp(document, 'onvisibilitychange', null);
108+ defineProp(window, 'onpagehide', null);
109+ defineProp(window, 'onblur', null);
88110 } catch(e) {}
89111
90112 // 2. Intercept registration of visibility pause event listeners
91113 const origAddEventListener = EventTarget.prototype.addEventListener;
92114 EventTarget.prototype.addEventListener = function(type, listener, options) {
93- if (type === 'visibilitychange' || type === 'webkitvisibilitychange' || type === 'pagehide') {
115+ if (type === 'visibilitychange' || type === 'webkitvisibilitychange' || type === 'pagehide' || type === 'blur' ) {
94116 return;
95117 }
96118 return origAddEventListener.apply(this, arguments);
97119 };
98120
99- // 3. Suppress any existing or bubbling visibilitychange & blur events
100- const suppressEvents = ['visibilitychange', 'webkitvisibilitychange', 'pagehide', 'blur'];
121+ // 3. Suppress any bubbling visibilitychange & blur events
122+ const suppressEvents = ['visibilitychange', 'webkitvisibilitychange', 'pagehide', 'blur', 'freeze' ];
101123 suppressEvents.forEach(function(evt) {
102124 window.addEventListener(evt, function(e) {
103125 if (e && e.stopImmediatePropagation) e.stopImmediatePropagation();
126+ if (e && e.stopPropagation) e.stopPropagation();
104127 }, true);
105128 document.addEventListener(evt, function(e) {
106129 if (e && e.stopImmediatePropagation) e.stopImmediatePropagation();
130+ if (e && e.stopPropagation) e.stopPropagation();
107131 }, true);
108132 });
109133 } catch(e) {}
0 commit comments