Skip to content

Instantly share code, notes, and snippets.

@SocksTheWolf
Last active May 28, 2026 00:09
Show Gist options
  • Select an option

  • Save SocksTheWolf/822155d955661416df1dde5a48cb3e73 to your computer and use it in GitHub Desktop.

Select an option

Save SocksTheWolf/822155d955661416df1dde5a48cb3e73 to your computer and use it in GitHub Desktop.
Userscript for allowing for lurking as a Twitch user. Press the Raw button to trigger install.
// ==UserScript==
// @name TwitchAllowLurks
// @namespace https://socksthewolf.com/
// @version 0.2.4
// @description Disable HTML5 Page Visibility API to prevent Twitch ads from stopping lurks
// @author kookxiang (code) & socksthewolf (config)
// @match https://twitch.tv/*
// @match https://m.twitch.tv/*
// @match https://www.twitch.tv/*
// @exclude https://www.twitch.tv/popout/*/guest-star
// @exclude https://www.twitch.tv/settings/*
// @grant none
// @run-at document-start
// @downloadURL https://gist.githubusercontent.com/SocksTheWolf/822155d955661416df1dde5a48cb3e73/raw/twitchallowlurks.user.js
// ==/UserScript==
// stop visibility monitoring events
document.addEventListener('visibilitychange', function (e) { e.stopImmediatePropagation(); }, true);
// disable unfocus events
window.addEventListener('blur', function (e) { e.stopImmediatePropagation(); }, true);
// override document.visibilityState to always return the page is visible
Object.defineProperty(document, 'visibilityState', { get: function () { return "visible"; } });
// override document.hidden to always return that the page is rendering
Object.defineProperty(document, 'hidden', { get: function () { return false; } });
@SocksTheWolf

SocksTheWolf commented Mar 15, 2026

Copy link
Copy Markdown
Author

Click here to install

You must have an userscript runner installed. Literally every modern browser made in the last decade and a half has one.


Kitbashed from this: https://greasyfork.org/en/scripts/415290-disable-page-visibility-api/code

I just added twitch urls as matches + updated namespace to avoid collisions. Edited this entirely on my phone.

@SocksTheWolf

Copy link
Copy Markdown
Author

Updated script with a few excludes locations (disables this code from running the on guest star page and your settings pages), and inlined comments into script so it's clear what the script does.

@SlyAceZeta

Copy link
Copy Markdown

Huge thanks for this, I hope this will help! Much prefer a solution like this over a browser-wide extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment