Skip to content

Commit

Permalink
🐛 修复常量值被改变的问题 #214
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Jul 27, 2023
1 parent 0bbe7ce commit 63d3061
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/runtime/background/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ export async function dealXhr(
LoggerCore.getLogger(Logger.E(e)).error("GM XHR response error");
}
try {
respond.responseText = xhr.responseText;
respond.responseText = xhr.responseText || undefined;
} catch (e) {
LoggerCore.getLogger(Logger.E(e)).error("GM XHR getResponseText error");
}
Expand Down
8 changes: 8 additions & 0 deletions src/runtime/content/exec_script.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,12 @@ describe("sandbox", () => {
const ret = sandboxExec.exec();
expect(ret).toEqual("ok3");
});

// 沉浸式翻译, 常量值被改变
it("NodeFilter #214", () => {
scriptRes2.code = `return NodeFilter.FILTER_REJECT;`;
sandboxExec.scriptFunc = compileScript(compileScriptCode(scriptRes2));
const ret = sandboxExec.exec();
expect(ret).toEqual(2);
});
});
1 change: 0 additions & 1 deletion src/runtime/content/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ describe("proxy context", () => {
});

describe("兼容问题", () => {
console.log("ok");
const _this = proxyContext({}, {});
// https://github.com/xcanwin/KeepChatGPT 环境隔离得不够干净导致的
it("Uncaught TypeError: Illegal invocation #189", () => {
Expand Down
1 change: 1 addition & 0 deletions src/runtime/content/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export const init = new Map<string, boolean>();

// 需要用到全局的
export const unscopables: { [key: string]: boolean } = {
NodeFilter: true,
RegExp: true,
};

Expand Down

0 comments on commit 63d3061

Please sign in to comment.