Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
294a04b
重构 `GM_xmlhttpRequest` 及相关代码
cyfung1031 Nov 2, 2025
5397a85
刪無用代碼
cyfung1031 Nov 2, 2025
4e80910
mock修正
cyfung1031 Nov 2, 2025
1f92f41
重构 `GM_donwload`
cyfung1031 Nov 3, 2025
86b1502
GM_download: 跟随TM,改使用 fetch
cyfung1031 Nov 3, 2025
7e4f5cc
`GM_download` 代码修正
cyfung1031 Nov 3, 2025
e52d4be
`GM_download` 代码调整
cyfung1031 Nov 3, 2025
c1ce6a8
`GM_xmlhttpRequest` 修正 `context`;`GM_download` 新增 `context`, `user`, …
cyfung1031 Nov 3, 2025
dc90065
代码调整,避免参考无法GC回收
cyfung1031 Nov 3, 2025
c410be8
支持 `binary: true`
cyfung1031 Nov 3, 2025
9f8ad72
Merge branch 'main' into pr/cyfung1031/901
CodFrm Nov 5, 2025
bb5c428
添加单元测试
CodFrm Nov 5, 2025
5dc7473
定义成常量赋予含义
cyfung1031 Nov 6, 2025
266cb5b
不用可以直接删
cyfung1031 Nov 6, 2025
4827904
没地方引用dealXhrResponse了,可以直接删
cyfung1031 Nov 6, 2025
f7fbceb
修正response空值问题
cyfung1031 Nov 6, 2025
91ce95b
新增 GM xhr API 黑名单判断 (与TM一致)
cyfung1031 Nov 6, 2025
1e02ab8
单元测试更改成 concurrent
cyfung1031 Nov 6, 2025
57eab2a
单元测试代码调整
cyfung1031 Nov 6, 2025
3677003
FF兼容调整
cyfung1031 Nov 7, 2025
0739574
FF兼容调整
cyfung1031 Nov 7, 2025
6b19a4a
代码清理一下
cyfung1031 Nov 8, 2025
ae6b382
整理单元测试mock
CodFrm Nov 12, 2025
d19bc6c
整理代码结构
CodFrm Nov 12, 2025
36ad26a
删除byPass逻辑,避免饶过的可能
CodFrm Nov 12, 2025
db8642e
通过单元测试
CodFrm Nov 12, 2025
7e2ff63
改善了reqID关联的代码设计
cyfung1031 Nov 13, 2025
9c8b4f1
typescript 要 return undefined
cyfung1031 Nov 13, 2025
091a984
修正 lastNwReqTriggerTime
cyfung1031 Nov 13, 2025
7ebea0b
修正
cyfung1031 Nov 13, 2025
1fc53ea
中文注释
cyfung1031 Nov 13, 2025
73ac04b
删旧代码
cyfung1031 Nov 13, 2025
776844a
抽出成 generateUniqueMarkerID
cyfung1031 Nov 13, 2025
1ee5916
中文注释
cyfung1031 Nov 13, 2025
ab5389f
修正错误处理
cyfung1031 Nov 13, 2025
4ac2789
异常处理: nwReqExecute 过时处理
cyfung1031 Nov 13, 2025
71da4ca
时间值条件修改
cyfung1031 Nov 13, 2025
698d762
勉强无幸福,只好退回
cyfung1031 Nov 13, 2025
9a72467
整理结构
CodFrm Nov 14, 2025
7a1ae30
测试脚本
CodFrm Nov 14, 2025
de41130
整理
CodFrm Nov 14, 2025
f19a4be
整理定义
CodFrm Nov 14, 2025
aa3cfd9
整理fetch xhr
CodFrm Nov 14, 2025
6d67d1d
整理
cyfung1031 Nov 14, 2025
79c4334
删除不使用的方法
CodFrm Nov 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,292 changes: 1,292 additions & 0 deletions example/tests/gm_xhr_test.js

Large diffs are not rendered by default.

56 changes: 25 additions & 31 deletions packages/chrome-extension-mock/web_reqeuest.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,8 @@
import EventEmitter from "eventemitter3";

export default class WebRequest {
sendHeader?: (details: chrome.webRequest.OnSendHeadersDetails) => chrome.webRequest.BlockingResponse | void;

mockXhr(xhr: any): any {
return () => {
const ret = new xhr();
const header: chrome.webRequest.HttpHeader[] = [];
ret.setRequestHeader = (k: string, v: string) => {
header.push({
name: k,
value: v,
});
};
const oldSend = ret.send.bind(ret);
ret.send = (data: any) => {
header.push({
name: "cookie",
value: "website=example.com",
});
const resp = this.sendHeader?.({
method: ret.method,
url: ret.url,
requestHeaders: header,
initiator: chrome.runtime.getURL(""),
} as chrome.webRequest.OnSendHeadersDetails) as chrome.webRequest.BlockingResponse;
resp.requestHeaders?.forEach((h) => {
ret._authorRequestHeaders!.addHeader(h.name, h.value);
});
oldSend(data);
};
return ret;
};
}

onBeforeSendHeaders = {
addListener: (callback: any) => {
this.sendHeader = callback;
Expand All @@ -49,4 +20,27 @@ export default class WebRequest {
// TODO
},
};

onBeforeRequest = {
counter: 0,
EE: new EventEmitter<string, any>(),
addListener: function (callback: (...args: any[]) => any) {
this.EE.addListener("onBeforeRequest", (params) => {
callback(params);
});
// TODO
},
};

onBeforeRedirect = {
addListener: () => {
// TODO
},
};

onErrorOccurred = {
addListener: () => {
// TODO
},
};
}
6 changes: 3 additions & 3 deletions src/app/service/content/create_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { type ScriptRunResource } from "@App/app/repo/scripts";
import { v4 as uuidv4 } from "uuid";
import type { Message } from "@Packages/message/types";
import EventEmitter from "eventemitter3";
import { GMContextApiGet } from "./gm_context";
import { createGMBase } from "./gm_api";
import { protect } from "./gm_context";
import { GMContextApiGet } from "./gm_api/gm_context";
import { protect } from "./gm_api/gm_context";
import { isEarlyStartScript } from "./utils";
import { ListenerManager } from "./listener_manager";
import { createGMBase } from "./gm_api/gm_api";

// 构建沙盒上下文
export const createContext = (
Expand Down
4 changes: 2 additions & 2 deletions src/app/service/content/exec_script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { compileScript } from "./utils";
import type { Message } from "@Packages/message/types";
import type { ScriptLoadInfo } from "../service_worker/types";
import type { ValueUpdateDataEncoded } from "./types";
import { evaluateGMInfo } from "./gm_info";
import { type IGM_Base } from "./gm_api";
import { evaluateGMInfo } from "./gm_api/gm_info";
import type { IGM_Base } from "./gm_api/gm_api";

// 执行脚本,控制脚本执行与停止
export default class ExecScript {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, expect, it, vi } from "vitest";
import ExecScript from "./exec_script";
import type { ScriptLoadInfo } from "../service_worker/types";
import type { GMInfoEnv, ScriptFunc } from "./types";
import { compileScript, compileScriptCode } from "./utils";
import ExecScript from "../exec_script";
import type { ScriptLoadInfo } from "@App/app/service/service_worker/types";
import type { GMInfoEnv, ScriptFunc } from "../types";
import { compileScript, compileScriptCode } from "../utils";
import type { Message } from "@Packages/message/types";
import { encodeMessage } from "@App/pkg/utils/message_value";
import { v4 as uuidv4 } from "uuid";
Expand Down
Loading
Loading