Skip to content

Commit 43b407a

Browse files
committed
🐛 修复后台脚本无法使用responseType的问题 #108
1 parent 2cac37f commit 43b407a

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/runtime/background/gm_api.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,17 @@ export default class GMApi {
106106
if (this.permissionVerify instanceof PermissionVerify) {
107107
listenerWebRequest(this.systemConfig.scriptCatFlag);
108108
}
109+
// 处理sandbox来的CAT_fetchBlob和CAT_createBlobUrl
110+
this.message.setHandler("CAT_createBlobUrl", (_: string, blob: Blob) => {
111+
const url = URL.createObjectURL(blob);
112+
setTimeout(() => {
113+
URL.revokeObjectURL(url);
114+
}, 60 * 1000);
115+
return Promise.resolve(url);
116+
});
117+
this.message.setHandler("CAT_fetchBlob", (_: string, url: string) => {
118+
return fetch(url).then((data) => data.blob());
119+
});
109120
}
110121

111122
// 解析请求

src/runtime/content/content.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ export default class ContentRuntime {
8181
this.contentMessage.setHandler(
8282
"CAT_createBlobUrl",
8383
(_action, data: Blob) => {
84-
return Promise.resolve(URL.createObjectURL(data));
84+
const url = URL.createObjectURL(data);
85+
setTimeout(() => {
86+
URL.revokeObjectURL(url);
87+
}, 60 * 1000);
88+
return Promise.resolve(url);
8589
}
8690
);
8791
}

0 commit comments

Comments
 (0)