0

我每秒运行一次 tampermonkey 脚本 - 向服务器发出请求以获取数据,数据只有大约 0.1% 的时间存在,当数据存在时 - 它正在使用 jQuery $.ajax 发出另一个 ajax 请求

现在,运行它会使 Firefox 每 1.5-2 小时增长约 1GB,并最终在几个小时内崩溃。

脚本很简单,它测试一个字符串的网址,如果它在那里 - 它测试: res.responseText.length == 36 && $('#xxxxx').length (第二部分测试用户是否仍然登录到网站)和然后发出api请求。

我尝试了大约 30 个版本 - 这是我能做的最好的版本 :( - 更糟糕的是每隔几分钟就会增加 1gb 内存 :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(当前) TamperMonkey 4.9.5941(当前)

4

0 回答 0