Skip to content

Commit 1f29e69

Browse files
committed
🐛 修复GM XHR 重定向丢失header的问题 #664
close #664
1 parent 6404c8f commit 1f29e69

4 files changed

Lines changed: 7 additions & 7 deletions

File tree

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ ScriptCat(脚本猫)是一个功能强大的用户脚本管理器,基于
6868
| Chrome | [正式版本](https://chrome.google.com/webstore/detail/scriptcat/ndcooeababalnlpkfedmmbbbgkljhpjf) [Beta版本](https://chromewebstore.google.com/detail/%E8%84%9A%E6%9C%AC%E7%8C%AB-beta/jaehimmlecjmebpekkipmpmbpfhdacom?authuser=0&hl=zh-CN) | ✅ 可用 |
6969
| Edge | [正式版本](https://microsoftedge.microsoft.com/addons/detail/scriptcat/liilgpjgabokdklappibcjfablkpcekh) [Beta版本](https://microsoftedge.microsoft.com/addons/detail/scriptcat-beta/nimmbghgpcjmeniofmpdfkofcedcjpfi) | ✅ 可用 |
7070
| Firefox | [正式版本](https://addons.mozilla.org/zh-CN/firefox/addon/scriptcat/) [Beta版本](https://addons.mozilla.org/zh-CN/firefox/addon/scriptcat-pre/) | ✅ MV2 |
71-
| GitHub Releases | [GitHub Releases](https://github.com/scriptscat/scriptcat/releases) | ✅ 可用 |
72-
| GitHub Actions | [GitHub Actions](https://github.com/scriptscat/scriptcat/actions/workflows/build.yaml) | 每次提交触发 |
7371

7472
#### 手动安装
7573

README_EN.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ ScriptCat is a powerful userscript manager based on Tampermonkey's design philos
6868
| Chrome | [Stable Version](https://chrome.google.com/webstore/detail/scriptcat/ndcooeababalnlpkfedmmbbbgkljhpjf) [Beta Version](https://chromewebstore.google.com/detail/%E8%84%9A%E6%9C%AC%E7%8C%AB-beta/jaehimmlecjmebpekkipmpmbpfhdacom?authuser=0&hl=zh-CN) | ✅ Available |
6969
| Edge | [Stable Version](https://microsoftedge.microsoft.com/addons/detail/scriptcat/liilgpjgabokdklappibcjfablkpcekh) [Beta Version](https://microsoftedge.microsoft.com/addons/detail/scriptcat-beta/nimmbghgpcjmeniofmpdfkofcedcjpfi) | ✅ Available |
7070
| Firefox | [Stable Version](https://addons.mozilla.org/zh-CN/firefox/addon/scriptcat/) [Beta Version](https://addons.mozilla.org/zh-CN/firefox/addon/scriptcat-pre/) | ✅ MV2 |
71-
| GitHub Releases | [GitHub Releases](https://github.com/scriptscat/scriptcat/releases) | ✅ Available |
72-
| GitHub Actions | [GitHub Actions](https://github.com/scriptscat/scriptcat/actions/workflows/build.yaml) | Triggered on every commit |
7371

7472
#### Manual Installation
7573

README_RU.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ ScriptCat — это мощный менеджер пользовательск
5757
| Chrome | [Стабильная версия](https://chrome.google.com/webstore/detail/scriptcat/ndcooeababalnlpkfedmmbbbgkljhpjf) / [Beta](https://chromewebstore.google.com/detail/%E8%84%9A%E6%9C%AC%E7%8C%AB-beta/jaehimmlecjmebpekkipmpmbpfhdacom) | ✅ Доступно |
5858
| Edge | [Стабильная версия](https://microsoftedge.microsoft.com/addons/detail/scriptcat/liilgpjgabokdklappibcjfablkpcekh) / [Beta](https://microsoftedge.microsoft.com/addons/detail/scriptcat-beta/nimmbghgpcjmeniofmpdfkofcedcjpfi) | ✅ Доступно |
5959
| Firefox | [Стабильная версия](https://addons.mozilla.org/firefox/addon/scriptcat/) / [Beta](https://addons.mozilla.org/firefox/addon/scriptcat-pre/) | ✅ MV2 |
60-
| GitHub Releases | [GitHub Releases](https://github.com/scriptscat/scriptcat/releases) | ✅ Доступно |
61-
| GitHub Actions | [GitHub Actions](https://github.com/scriptscat/scriptcat/actions/workflows/build.yaml) | Запускается при каждом коммите |
6260

6361
#### Ручная установка
6462
Если доступ к магазину расширений невозможен, вы можете скачать ZIP-архив последней версии с [GitHub Releases](https://github.com/scriptscat/scriptcat/releases) и установить его вручную.

src/app/service/service_worker/gm_api.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,9 @@ export default class GMApi {
732732
};
733733
let finalUrl = "";
734734
// 等待response
735+
this.cache.set("gmXhrRequest:params:" + requestId, {
736+
redirect: params.redirect,
737+
});
735738
this.gmXhrHeadersReceived.addListener(
736739
"headersReceived:" + requestId,
737740
(details: chrome.webRequest.OnHeadersReceivedDetails) => {
@@ -1211,7 +1214,9 @@ export default class GMApi {
12111214
}
12121215
}
12131216
});
1214-
if (location) {
1217+
const params = this.cache.get("gmXhrRequest:params:" + requestId) as GMSend.XHRDetails;
1218+
// 如果是重定向,并且不是manual模式,则需要重新设置dnr规则
1219+
if (location && params.redirect !== "manual") {
12151220
// 处理重定向后的unsafeHeader
12161221
const rule = this.cache.get("dnrRule:" + requestId) as chrome.declarativeNetRequest.Rule;
12171222
// 修改匹配链接
@@ -1233,6 +1238,7 @@ export default class GMApi {
12331238
this.cache.delete("gmXhrRequest:" + details.requestId);
12341239
this.cache.delete("dnrRule:" + requestId);
12351240
this.cache.delete("gmXhrRequest:finalUrl:" + requestId);
1241+
this.cache.delete("gmXhrRequest:params:" + requestId);
12361242
chrome.declarativeNetRequest.updateSessionRules({
12371243
removeRuleIds: [parseInt(requestId)],
12381244
});

0 commit comments

Comments
 (0)