Auto refresh page when specific text detected - Twitch monitoring with notifications

Hey everyone! I need help creating a monitoring script for Twitch streams. My English isn’t great but I hope you can understand what I’m trying to do.

What I want:
A script that checks a Twitch page every 15 seconds for certain words like “LIVE” or “5000” (error code). When it finds these words, it should refresh the page once, send me a notification, and then stop running.

Why I need this:
I keep multiple Twitch channels open in different tabs for hours. Sometimes I get the “This video is not available (Error #5000)” message, or I miss when streamers go live. I want to catch both situations automatically.

Requirements:

  • Check page content every 15 seconds (custom interval would be nice)
  • Search for multiple keywords
  • Auto-refresh when text is found
  • Push notification before refresh
  • Stop after one detection
  • Work in background across multiple tabs

I tried using Tampermonkey but my code doesn’t work properly:

(function() {
    'use strict';
    
    setInterval(function() {
        var searchTerm = "LIVE";
        var errorCode = "5000";
        
        if(document.body.innerText.includes(searchTerm) || document.body.innerText.includes(errorCode)) {
            alert("Detected: " + searchTerm);
            window.location.reload();
        }
    }, 15000);
})();

Any better solutions or fixes would be amazing! Thanks!

script looks good, but twitch loads content dynamically so document.body.innerText might miss things. use querySelector to target specific elements where “LIVE” or error messages show up. add a flag variable to kill the interval after first detection - otherwise it’ll keep running after refresh.

the main issue is twitch’s spa architecture breaking normal dom checks. wrap your search in try-catch and add window.clearInterval() once detection triggers - you’re likely creating memory leaks across tabs. also check document.readyState before scanning content.

Your script’s hitting the main issue with Twitch - it’s React-based so content changes without page reloads. I’ve run a similar setup for months and found that checking document.querySelector('[data-a-target="live-badge"]') works way better than searching all the body text for live status.

For error 5000, hunt for elements with class names that have “error” or “unavailable” in them. Also throw in a boolean flag like let hasDetected = false; at the top and wrap your detection code in if (!hasDetected) - stops it from triggering multiple times.

Heads up: browsers often block alerts, so try new Notification() instead if you enable browser notifications for the site. And Twitch has rate limiting - 15 seconds is fine but don’t go much lower or you’ll get temp blocked.

I’ve been doing the same thing with Twitch card drops and ran into this too. Your issue is that Twitch lazy loads everything - the content isn’t there when you check for it. Ditch the body text scanning and use MutationObserver instead. It’ll catch stuff as it loads rather than missing it between checks. For the 5000 errors, target the video player container directly since that’s where they show up. Also, throw your detection state into localStorage so it survives page refreshes. Otherwise your script resets every reload and you’ll get duplicate triggers. One last thing - Twitch shows cached content for a split second before updating, so add a short delay before doing anything. Saves you from false positives.