test
Some checks failed
test / Run tests (push) Failing after 12s
build / Build (push) Failing after 20s

This commit is contained in:
王一之 2025-03-16 08:17:18 +08:00
parent 99e33c18f6
commit fcd4682aff
2 changed files with 14 additions and 5 deletions

View File

@ -1,10 +1,9 @@
import { Group } from "@Packages/message/server";
import { Group, MessageConnect } from "@Packages/message/server";
export class GMApi {
constructor(private group: Group) {}
xmlHttpRequest(params: GMSend.XHRDetails) {
console.log(params);
xmlHttpRequest(params: GMSend.XHRDetails, con: MessageConnect | null) {
const xhr = new XMLHttpRequest();
xhr.open(params.method || "GET", params.url);
// 添加header
@ -14,7 +13,14 @@ export class GMApi {
}
}
xhr.onload = function () {
console.log(xhr, xhr.getAllResponseHeaders());
con?.sendMessage({
action: "onload",
data: {
status: xhr.status,
statusText: xhr.statusText,
response: xhr.responseText,
},
});
};
xhr.send();
}

View File

@ -153,7 +153,10 @@ export default class GMApi {
console.log("处理", details);
});
// 再发送到offscreen, 处理请求
connect(this.sender, "gmApi/xmlHttpRequest", request.params[0]);
const offscreenCon = await connect(this.sender, "gmApi/xmlHttpRequest", request.params[0]);
offscreenCon.onMessage((msg) => {
console.log("offscreenCon", msg);
});
}
start() {