Override documents hasFocus

Simple script to trick document to focus even if document is in background

  1. // ==UserScript==
  2. // @name Override documents hasFocus
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.1
  5. // @description Simple script to trick document to focus even if document is in background
  6. // @author Neeraj Khandelwal
  7. // @match *://*/*
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. setTimeout(() => {
  17. window.in_focus = 1;
  18. document.hasFocus = () => true;
  19. }, 500);
  20. })();