From 7d45435883cc54802b227bdb5fcd3e3922b65830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Thu, 18 Apr 2024 10:46:29 +0800 Subject: [PATCH] =?UTF-8?q?optimize:=20global.script=E5=8F=AA=E6=9C=89?= =?UTF-8?q?=E5=9C=A8=E5=8A=A0=E8=BD=BD=E5=86=85=E7=BD=AEgithub=E6=B2=B9?= =?UTF-8?q?=E7=8C=B4=E6=97=B6=EF=BC=8C=E6=89=8D=E9=9C=80=E8=A6=81=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mitmproxy/src/lib/interceptor/impl/res/script.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/mitmproxy/src/lib/interceptor/impl/res/script.js b/packages/mitmproxy/src/lib/interceptor/impl/res/script.js index b6ed09c5..0994266f 100644 --- a/packages/mitmproxy/src/lib/interceptor/impl/res/script.js +++ b/packages/mitmproxy/src/lib/interceptor/impl/res/script.js @@ -33,8 +33,10 @@ module.exports = { keys = [keys] } try { + // 内置脚本 const scripts = monkey.get(setting.script.dirAbsolutePath) - let tags = '\r\n\t' + getScript('global', scripts.global.script) + + let tags = '' for (const key of keys) { if (key === 'global') { continue @@ -49,11 +51,19 @@ module.exports = { if (script == null) { continue } + if (key === 'github') { + // 如果是github油猴脚本,需要先加载 `global.script`,避免 `GM_xxx` 方法不存在导致报错。 + tags += '\r\n\t' + getScript('global', scripts.global.script) + } scriptTag = getScript(key, script.script) // 2.DS内置脚本 } tags += '\r\n\t' + scriptTag } + + // 如果脚本为空,则不插入 + if (tags === '') return + res.setHeader('DS-Script-Interceptor', 'true') log.info('script response intercept: insert script', rOptions.hostname, rOptions.path, ', head:', tags) return {