Questions & Answers

How can I make setInterval work even when the tab in Chrome is inactive?

Please help me figure it out. I am writing a custom script for Tampermonkey.

Briefly about the script: the script updates the page on the site every 3 minutes, checks for the presence of an object and, if there is one, clicks on it.

Problem: when the tab is inactive (focus on another Google tab or the window is minimized), the script does not work, the setInterval and setTimeout timer stop working and the script does not update or search for anything. How to fix this situation?

// ==UserScript==
// @name         User Script
// @namespace
// @version      0.1
// @description  try to take over the world!
// @author       None
// @match
// @icon
// @require
// @grant        none
/* globals jQuery, $, waitForKeyElements */
// ==/UserScript==

    'use strict';


        function SearchController(){
            var i = 0;
            var result = '';
                if ($(this).find('button').find('.phMMp').text() == 'Click'){

        }, 60000);

    }, 4000);


I know about this thing (, but for some reason it doesn't work in Tampermonkey.

2023-01-07 20:33:09
2023-01-07 20:33:09
@wOxxOm, Thank you so much for the article. How to translate the code to JQ? With "React.js" I don't know how to use
Answers(0) :