Skip to content

Commit 63d3061

Browse files
committed
🐛 修复常量值被改变的问题 #214
1 parent 0bbe7ce commit 63d3061

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

src/runtime/background/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ export async function dealXhr(
388388
LoggerCore.getLogger(Logger.E(e)).error("GM XHR response error");
389389
}
390390
try {
391-
respond.responseText = xhr.responseText;
391+
respond.responseText = xhr.responseText || undefined;
392392
} catch (e) {
393393
LoggerCore.getLogger(Logger.E(e)).error("GM XHR getResponseText error");
394394
}

src/runtime/content/exec_script.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,12 @@ describe("sandbox", () => {
9797
const ret = sandboxExec.exec();
9898
expect(ret).toEqual("ok3");
9999
});
100+
101+
// 沉浸式翻译, 常量值被改变
102+
it("NodeFilter #214", () => {
103+
scriptRes2.code = `return NodeFilter.FILTER_REJECT;`;
104+
sandboxExec.scriptFunc = compileScript(compileScriptCode(scriptRes2));
105+
const ret = sandboxExec.exec();
106+
expect(ret).toEqual(2);
107+
});
100108
});

src/runtime/content/utils.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ describe("proxy context", () => {
4141
});
4242

4343
describe("兼容问题", () => {
44-
console.log("ok");
4544
const _this = proxyContext({}, {});
4645
// https://github.com/xcanwin/KeepChatGPT 环境隔离得不够干净导致的
4746
it("Uncaught TypeError: Illegal invocation #189", () => {

src/runtime/content/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export const init = new Map<string, boolean>();
123123

124124
// 需要用到全局的
125125
export const unscopables: { [key: string]: boolean } = {
126+
NodeFilter: true,
126127
RegExp: true,
127128
};
128129

0 commit comments

Comments
 (0)