Skip to content

Comment on Ask HN: Is YouTube using a dark pattern to prevent background playlist play?parent

Comments

I quickly did something like this for Twitch, seems to work:

    document.hasFocus = function() {
      return true;
    }
    Object.defineProperty(document, 'hasFocus', {value: true})
    
    document.hidden = function() {
      return false;
    }
    //Object.defineProperty(document, 'hidden', {value: false})
    Object.defineProperty(document, "hidden", {get: function() { return false; }
    });
    
    document.webkitHidden = function() {
      return false;
    }
    Object.defineProperty(document, 'webkitHidden', {value: false})
    
    document.addEventListener("focus", function(e) {
      e.stopPropagation();
      e.stopImmediatePropagation();
      e.preventDefault();
      return false;
    }, true);
    
    document.addEventListener("visibilitychange", function(e) {
      e.stopPropagation();
      e.stopImmediatePropagation();
      e.preventDefault();
      return false;
    }, true);
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.