0

I have running tampermonkey script running every seconds - doing request to server to get data, data is there only around 0.1% of time, when data is there - it is making another ajax request using jQuery $.ajax

Now, running this is making firefox grow about 1GB every 1,5-2h and eventually crashing in few hours.

script is simple, it tests web address for a string and if its there - it tests: res.responseText.length == 36 && $('#xxxxx').length (second part tests if user is still logged to website) and then making api request.

i tried around 30 versions - this one is the best one i could make :( - worse one was about 1gb memory grow every few minutes :D

// ==UserScript==
// @name         xxxx
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://xxxx.xx/
// @grant        GM_xmlhttpRequest
// @require https://xxx.xx/content/js/jquery-3.1.1.min.js
// @require https://xxx.xx/content/js/jquery.cookie.js
// ==/UserScript==
function xxxxxxxxx() {
            GM_xmlhttpRequest({
            method: "GET",
            url: "http://xxx.xxx.xxx.xxx/api.php?method=data&action=getData",
            onload: function (res) {
//VALID only ~0.1% of time
                if (res.responseText.length == 36 &&         $('#xxxxx').length) {
                    $.ajax({
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        headers: {
                            "X-XSRF-TOKEN": $.cookie("XSRF-TOKEN-VALUE")
                        },
                        data: JSON.stringify({'data': res.responseText}),
                        url: "https://xxxx.xxx.xx",
                        onload: function (result) {
                            console.log(result.responseText);
                        }
                    });
                }
                res = undefined;
                delete (res);
            },
            onerror: function () {
            //nothing
            }
        });
    }


(function () {
    'use strict';
    //only running if correct website with #
    if (!/#\/xxxxxx.*/.test(location.hash)) return;

    //running every seconds
    setInterval(xxxxxxxxx, 1000);
    //reload page every 10 minutes  
    setInterval(function () {
        location.reload();
    }, 360 * 1000);
})();

Firefox 66.0.5 (current) TamperMonkey 4.9.5941 (current)

Krzysztof
  • 189
  • 1
  • 10
  • 1
    Sounds like a bug in FF or in Tampermonkey. Try an older/newer version of both (e.g. TM beta). – wOxxOm May 20 '19 at 10:28
  • thanks for suggestion, i tried firefox developer edition - it was the same, but then i switched to chrome and after ~3hours RAM usage grow up by ~40% - so its like 4x better then in firefox, with exactly same script (copied 1 to 1 from Firefox to Chrome) – Krzysztof May 20 '19 at 16:59
  • another update - after another ~12-16hours - firefox crashed twice (grow to ~3GB and crashed), chrome stays at the same level (around 40% more ram used then after initial startup, but its not growing anymore). Shame i have to switch from firefox to chrome :( – Krzysztof May 21 '19 at 09:59
  • Try switching to Violentmonkey or Greasemonkey (note GM4 has changed all gm* functions) – wOxxOm May 21 '19 at 10:52

0 Answers0