scripts(reporter): fix stable

This commit is contained in:
verysillycat 2024-08-14 21:58:09 -06:00
parent 62c08441bc
commit 2e92c45447

View file

@ -35,24 +35,6 @@ for (const variable of ["DISCORD_TOKEN", "CHROMIUM_BIN"]) {
const CANARY = process.env.USE_CANARY === "true"; const CANARY = process.env.USE_CANARY === "true";
const browser = await pup.launch({
headless: true,
executablePath: process.env.CHROMIUM_BIN,
args: [
'--disable-dev-shm-usage',
'--shm-size=4gb'
]
});
const page = await browser.newPage();
await page.setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36");
await page.setBypassCSP(true);
async function maybeGetError(handle: JSHandle): Promise<string | undefined> {
return await (handle as JSHandle<Error>)?.getProperty("message")
.then(m => m?.jsonValue())
.catch(() => undefined);
}
const report = { const report = {
badPatches: [] as { badPatches: [] as {
plugin: string; plugin: string;
@ -184,7 +166,36 @@ async function printReport() {
} }
} }
page.on("console", async e => { async function maybeGetError(handle: JSHandle): Promise<string | undefined> {
return await (handle as JSHandle<Error>)?.getProperty("message")
.then(m => m?.jsonValue())
.catch(() => undefined);
}
async function reporterRuntime(token: string) {
Vencord.Webpack.waitFor(
"loginToken",
m => {
console.log("[PUP_DEBUG]", "Logging in with token...");
m.loginToken(token);
}
);
}
try {
const browser = await pup.launch({
headless: true,
executablePath: process.env.CHROMIUM_BIN,
args: [
'--disable-dev-shm-usage',
'--shm-size=4gb'
]
});
const page = await browser.newPage();
await page.setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36");
await page.setBypassCSP(true);
page.on("console", async e => {
const level = e.type(); const level = e.type();
const rawArgs = e.args(); const rawArgs = e.args();
@ -288,35 +299,30 @@ page.on("console", async e => {
} }
} }
} }
}); });
page.on("error", e => console.error("[Error]", e.message));
page.on("pageerror", e => {
if (e.message.includes("Sentry successfully disabled")) return;
page.on("error", e => console.error("[Error]", e.message));
page.on("pageerror", e => {
if (!e.message.startsWith("Object") && !e.message.includes("Cannot find module")) { if (!e.message.startsWith("Object") && !e.message.includes("Cannot find module")) {
console.error("[Page Error]", e.message); console.error("[Page Error]", e.message);
report.otherErrors.push(e.message); report.otherErrors.push(e.message);
} else { } else {
report.ignoredErrors.push(e.message); report.ignoredErrors.push(e.message);
} }
}); });
async function reporterRuntime(token: string) { await page.evaluateOnNewDocument(`
Vencord.Webpack.waitFor(
"loginToken",
m => {
console.log("[PUP_DEBUG]", "Logging in with token...");
m.loginToken(token);
}
);
}
await page.evaluateOnNewDocument(`
if (location.host.endsWith("discord.com")) { if (location.host.endsWith("discord.com")) {
${readFileSync("./dist/browser/browser.js", "utf-8")}; ${readFileSync("./dist/browser/browser.js", "utf-8")};
(${reporterRuntime.toString()})(${JSON.stringify(process.env.DISCORD_TOKEN)}); (${reporterRuntime.toString()})(${JSON.stringify(process.env.DISCORD_TOKEN)});
} }
`); `);
await page.goto(CANARY ? "https://canary.discord.com/login" : "https://discord.com/login"); await page.goto(CANARY ? "https://canary.discord.com/login" : "https://discord.com/login");
await printReport();
await browser.close();
} catch (error) {
console.error("An error occurred:", error);
process.exit(1);
}