refactor: automatic proxy constructor

This commit is contained in:
velzie 2024-07-19 13:52:34 -04:00
parent eba3e759fd
commit 80d51ed7a7
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F
11 changed files with 192 additions and 131 deletions

View file

@ -1,18 +1,20 @@
import { decodeUrl } from "../../shared/rewriters/url";
import { client } from "..";
import { BareClient } from "../shared";
const client = new BareClient();
const bare = new BareClient();
WebSocket = new Proxy(WebSocket, {
construct(target, args) {
return client.createWebSocket(
args[0],
args[1],
target,
{
"User-Agent": navigator.userAgent,
Origin: new URL(decodeUrl(location.href)).origin,
},
ArrayBuffer.prototype
client.Proxy(window, "WebSocket", {
construct(ctx) {
ctx.return(
bare.createWebSocket(
ctx.args[0],
ctx.args[1],
ctx.fn as typeof WebSocket,
{
"User-Agent": navigator.userAgent,
Origin: client.url.origin,
},
ArrayBuffer.prototype
)
);
},
});