Skip to content

Commit c453d21

Browse files
committed
🐛 修复特殊属性导致的问题 #190
1 parent 146c9ed commit c453d21

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/runtime/content/utils.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { MessageManager } from "@App/app/message/message";
22
import { ScriptRunResouce } from "@App/app/repo/scripts";
33
import { v4 as uuidv4 } from "uuid";
4+
import { has } from "lodash";
45
import GMApi, { ApiValue, GMContext } from "./gm_api";
56

67
// 构建脚本运行代码
@@ -143,9 +144,11 @@ Object.keys(descs).forEach((key) => {
143144
// 拦截上下文
144145
export function proxyContext(global: any, context: any) {
145146
const special = Object.assign(writables);
147+
// 处理某些特殊的属性
146148
// 后台脚本要不要考虑不能使用eval?
147149
const thisContext: { [key: string]: any } = {
148150
eval: global.eval,
151+
define: undefined,
149152
};
150153
// keyword是与createContext时同步的,避免访问到context的内部变量
151154
const contextKeyword: { [key: string]: any } = {
@@ -184,7 +187,7 @@ export function proxyContext(global: any, context: any) {
184187
break;
185188
}
186189
if (typeof name === "string" && name !== "undefined") {
187-
if (thisContext[name]) {
190+
if (has(thisContext, name)) {
188191
return thisContext[name];
189192
}
190193
if (context[name]) {
@@ -230,7 +233,7 @@ export function proxyContext(global: any, context: any) {
230233
break;
231234
}
232235
if (typeof name === "string" && name !== "undefined") {
233-
if (thisContext[name]) {
236+
if (has(thisContext, name)) {
234237
return true;
235238
}
236239
if (context[name]) {

0 commit comments

Comments
 (0)