scriptcat
scriptcat copied to clipboard
扩展不定期崩溃, 内存溢出
浏览器版本: Edge 101.0.1210.32 (正式版本) (64 位) Scriptcat版本: 0.9.1 脚本数量3-5个, 可能每小时运行, 数据量大概几万条, 有些脚本会做成爬虫, 基本几天会崩溃一次 但是之前用油猴是没这问题的
方便发一下脚本看看么?

没看到什么特别的报错, 不过我在一个新的Edge浏览器, 只安装了scriptcat和油猴(版本4.16.1), 同时测试了一下, 脚本如下
Scriptcat脚本
// ==UserScript==
// @name New Userscript
// @namespace https://bbs.tampermonkey.net.cn/
// @version 0.1.0
// @description try to take over the world!
// @author You
// @require https://cdn.jsdelivr.net/npm/[email protected]/dist/gm.js
// @definition https://cdn.jsdelivr.net/npm/[email protected]/src/types/gm.d.ts
// @grant GM_xmlhttpRequest
// @grant GM_log
// @grant GM_setValue
// @grant GM_getValue
// @crontab */1 * * * *
// @connect https://s1.ax1x.com
// ==/UserScript==
let done;
gm.ajax({method:'get',url:'https://s1.ax1x.com/2022/05/26/XEW4te.png'})
.then(resp=>{
let count = GM_getValue('count',0);
GM_log(count++);
GM_setValue('count',count);
GM_log(JSON.stringify(resp).substr(0,1000));
console.log(resp);
done();
}).catch(e=>{
let count = GM_getValue('count',0);
GM_log(count++);
GM_setValue('count',count);
done();
});
return new Promise((resolve, reject) => {
// Your code here...
done = resolve;
});
油猴脚本
// ==UserScript==
// @name New Userscript
// @namespace https://bbs.tampermonkey.net.cn/
// @version 0.1.0
// @description try to take over the world!
// @author You
// @grant GM_xmlhttpRequest
// @grant GM_setValue
// @grant GM_getValue
// @include https://www.baidu.com/
// ==/UserScript==
setInterval(function(){
GM_xmlhttpRequest({
method:'get',
url:'https://s1.ax1x.com/2022/05/26/XEW4te.png',
onload:function(resp){
let count = GM_getValue('count',0);
console.log(count++);
GM_setValue('count',count);
console.log(JSON.stringify(resp).substr(0,1000));
console.log(resp);
}
});
},60*1000);
结果如下:
scriptcat运行了167次后崩溃, 显示内存溢出
油猴运行到200+都没事
请问还有什么需要我提供的吗?
目前还是会崩溃
请问还有什么需要我提供的吗? 目前还是会崩溃
暂时没了吧,还得去调试,近期可能修复不了,在准备一次大的重构,应该能解决这个问题。可能和现在的消息机制也有关系,之前开发的时候确实也没考虑内存泄漏的问题
扩展不稳定, 真是挺难受的. 不知道能不能先用一些其他野路子解决这个问题呢? 现在我是直接用ahk每天重启一遍edge..... https://stackoverflow.com/questions/13104360/how-to-restart-a-chrome-extension-automatically
想不到了,是必须用到后台脚本嘛?不是可以用暴力猴那些替代一下
不清楚op还关注这个么?今天测试了一下,代码中有将日志打到控制台 console.log(resp); 这个也会导致内存过大,我删除这一行后,使用下面的代码测试,发现确实是有内存泄漏问题(只是说没那么严重了),当停用脚本时内存恢复正常,这个问题会在最新版本去尝试修复
// ==UserScript==
// @name New Userscript
// @namespace https://bbs.tampermonkey.net.cn/
// @version 0.1.0
// @description try to take over the world!
// @author You
// @require https://cdn.jsdelivr.net/npm/[email protected]/dist/gm.js
// @definition https://cdn.jsdelivr.net/npm/[email protected]/src/types/gm.d.ts
// @grant GM_xmlhttpRequest
// @grant GM_log
// @grant GM_setValue
// @grant GM_getValue
// @crontab */5 * * * * *
// @connect https://s1.ax1x.com
// ==/UserScript==
let done;
gm.ajax({method:'get',url:'https://s1.ax1x.com/2022/05/26/XEW4te.png'})
.then(resp=>{
let count = GM_getValue('count',0);
GM_log(count++);
GM_setValue('count',count);
GM_log(JSON.stringify(resp).substr(0,1000));
// console.log(resp);
done();
}).catch(e=>{
let count = GM_getValue('count',0);
GM_log(count++);
GM_setValue('count',count);
done();
});
return new Promise((resolve, reject) => {
// Your code here...
done = resolve;
});



执行若干次后,内存波动正常
不过内存占用挺高的,后续继续优化
![]()
![]()
![]()
执行若干次后,内存波动正常
不过内存占用挺高的,后续继续优化
测试了下0.10.x版本, 比0.9.x的稳定, 但是依然会内存溢出
可以给一下脚本,或者执行频率么?
可以给一下脚本,或者执行频率么?
脚本不太方便给, 好多个脚本, 10分钟左右运行一次, 会下载, 处理xlsx/json, 然后上传
我用上面简单的脚本貌似也没法快速复现问题, 我也有点无奈
6点开始运行的脚本, 到现在3g了
有类似的脚本么?可以摘取一些关键代码,没有的话,比较难判断是不是脚本的内存泄漏问题
上述脚本,脚本5s会执行一次,上次测试80次,没有出现泄漏问题
因为后台脚本是持续的在一个页面中运行的,如果不对资源主动的释放是会很容易产生这个问题,我听哥哥的描述,脚本业务还是挺复杂的

上述脚本执行600次后,内存情况

我觉得大概率还是哥哥的代码问题,写后台脚本的时候确实要注意这内存释放的问题
哥哥也可以去油猴中文网贴一下相关代码或者关键代码https://bbs.tampermonkey.net.cn/,社区还是挺活跃的