Skip to content

Instantly share code, notes, and snippets.

@lchanouha
Created March 24, 2018 00:26
Show Gist options
  • Select an option

  • Save lchanouha/06b51423bc60693af216ebdce37d86a8 to your computer and use it in GitHub Desktop.

Select an option

Save lchanouha/06b51423bc60693af216ebdce37d86a8 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Disable Page Visibility API
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Disables JS events on whole page focus/unfocus. Usefull to prevent ads stop when switching to another tab.
// @author Louis Chanouha
// @match *://*/*
// @grant none
// ==/UserScript==
// Sourced from: https://stackoverflow.com/questions/47660653/chrome-extension-how-to-disable-page-visibility-api
// Tested on Google Chrome 64 / Tampermonkey (24/03/2018)
for (event_name of ["visibilitychange", "webkitvisibilitychange", "blur"]) {
window.addEventListener(event_name, function(event) {
event.stopImmediatePropagation();
}, true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment