2022-11-11 11:37:37 +00:00
|
|
|
/*
|
|
|
|
* Vencord, a modification for Discord's desktop app
|
|
|
|
* Copyright (c) 2022 Vendicated and contributors
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2024-06-01 02:28:58 +00:00
|
|
|
/* eslint-disable no-fallthrough */
|
|
|
|
|
2022-11-11 11:37:37 +00:00
|
|
|
// eslint-disable-next-line spaced-comment
|
|
|
|
/// <reference types="../src/globals" />
|
|
|
|
// eslint-disable-next-line spaced-comment
|
|
|
|
/// <reference types="../src/modules" />
|
|
|
|
|
|
|
|
import { readFileSync } from "fs";
|
2022-11-11 12:06:04 +00:00
|
|
|
import pup, { JSHandle } from "puppeteer-core";
|
|
|
|
|
|
|
|
for (const variable of ["DISCORD_TOKEN", "CHROMIUM_BIN"]) {
|
|
|
|
if (!process.env[variable]) {
|
|
|
|
console.error(`Missing environment variable ${variable}`);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
}
|
2022-11-11 11:37:37 +00:00
|
|
|
|
2022-12-20 01:59:16 +00:00
|
|
|
const CANARY = process.env.USE_CANARY === "true";
|
|
|
|
|
2022-11-11 11:37:37 +00:00
|
|
|
const browser = await pup.launch({
|
2023-11-25 00:32:21 +00:00
|
|
|
headless: "new",
|
2022-11-11 12:06:04 +00:00
|
|
|
executablePath: process.env.CHROMIUM_BIN
|
2022-11-11 11:37:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const page = await browser.newPage();
|
2022-12-20 01:59:16 +00:00
|
|
|
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");
|
2024-06-01 02:28:58 +00:00
|
|
|
await page.setBypassCSP(true);
|
2022-11-11 11:37:37 +00:00
|
|
|
|
2024-06-01 02:28:58 +00:00
|
|
|
async function maybeGetError(handle: JSHandle): Promise<string | undefined> {
|
|
|
|
return await (handle as JSHandle<Error>)?.getProperty("message")
|
|
|
|
.then(m => m?.jsonValue());
|
2022-11-11 11:37:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const report = {
|
|
|
|
badPatches: [] as {
|
|
|
|
plugin: string;
|
|
|
|
type: string;
|
|
|
|
id: string;
|
|
|
|
match: string;
|
|
|
|
error?: string;
|
|
|
|
}[],
|
|
|
|
badStarts: [] as {
|
|
|
|
plugin: string;
|
|
|
|
error: string;
|
|
|
|
}[],
|
2023-11-25 00:32:21 +00:00
|
|
|
otherErrors: [] as string[],
|
2024-06-01 02:28:58 +00:00
|
|
|
ignoredErrors: [] as string[],
|
2023-11-25 00:32:21 +00:00
|
|
|
badWebpackFinds: [] as string[]
|
2022-11-11 11:37:37 +00:00
|
|
|
};
|
|
|
|
|
2023-10-21 15:51:07 +00:00
|
|
|
const IGNORED_DISCORD_ERRORS = [
|
|
|
|
"KeybindStore: Looking for callback action",
|
|
|
|
"Unable to process domain list delta: Client revision number is null",
|
|
|
|
"Downloading the full bad domains file",
|
2023-11-25 00:32:21 +00:00
|
|
|
/\[GatewaySocket\].{0,110}Cannot access '/,
|
2024-03-27 13:39:58 +00:00
|
|
|
"search for 'name' in undefined",
|
|
|
|
"Attempting to set fast connect zstd when unsupported"
|
2023-10-21 15:51:07 +00:00
|
|
|
] as Array<string | RegExp>;
|
|
|
|
|
2024-06-12 21:30:11 +00:00
|
|
|
function toCodeBlock(s: string, indentation = 0, isDiscord = false) {
|
2022-11-11 11:37:37 +00:00
|
|
|
s = s.replace(/```/g, "`\u200B`\u200B`");
|
2024-06-12 21:30:11 +00:00
|
|
|
|
2024-06-12 22:15:26 +00:00
|
|
|
const indentationStr = Array(!isDiscord ? indentation : 0).fill(" ").join("");
|
|
|
|
return `\`\`\`\n${s.split("\n").map(s => indentationStr + s).join("\n")}\n${indentationStr}\`\`\``;
|
2022-11-11 11:37:37 +00:00
|
|
|
}
|
|
|
|
|
2022-11-11 12:27:44 +00:00
|
|
|
async function printReport() {
|
2023-11-25 00:32:21 +00:00
|
|
|
console.log();
|
|
|
|
|
2022-12-20 01:59:16 +00:00
|
|
|
console.log("# Vencord Report" + (CANARY ? " (Canary)" : ""));
|
2023-11-25 00:32:21 +00:00
|
|
|
|
2022-11-11 11:37:37 +00:00
|
|
|
console.log();
|
|
|
|
|
|
|
|
console.log("## Bad Patches");
|
|
|
|
report.badPatches.forEach(p => {
|
|
|
|
console.log(`- ${p.plugin} (${p.type})`);
|
|
|
|
console.log(` - ID: \`${p.id}\``);
|
2024-06-12 21:30:11 +00:00
|
|
|
console.log(` - Match: ${toCodeBlock(p.match, " - Match: ".length)}`);
|
|
|
|
if (p.error) console.log(` - Error: ${toCodeBlock(p.error, " - Error: ".length)}`);
|
2022-11-11 11:37:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
console.log();
|
|
|
|
|
2023-11-25 00:32:21 +00:00
|
|
|
console.log("## Bad Webpack Finds");
|
2024-06-12 21:30:11 +00:00
|
|
|
report.badWebpackFinds.forEach(p => console.log("- " + toCodeBlock(p, "- ".length)));
|
2023-11-25 00:32:21 +00:00
|
|
|
|
|
|
|
console.log();
|
|
|
|
|
2022-11-11 11:37:37 +00:00
|
|
|
console.log("## Bad Starts");
|
|
|
|
report.badStarts.forEach(p => {
|
|
|
|
console.log(`- ${p.plugin}`);
|
2024-06-12 21:30:11 +00:00
|
|
|
console.log(` - Error: ${toCodeBlock(p.error, " - Error: ".length)}`);
|
2022-11-11 11:37:37 +00:00
|
|
|
});
|
2022-11-11 12:06:04 +00:00
|
|
|
|
2023-11-25 00:32:21 +00:00
|
|
|
console.log();
|
|
|
|
|
2022-11-11 12:06:04 +00:00
|
|
|
console.log("## Discord Errors");
|
|
|
|
report.otherErrors.forEach(e => {
|
2024-06-12 21:30:11 +00:00
|
|
|
console.log(`- ${toCodeBlock(e, "- ".length)}`);
|
2022-11-11 12:06:04 +00:00
|
|
|
});
|
2022-11-11 12:27:44 +00:00
|
|
|
|
2023-11-25 00:32:21 +00:00
|
|
|
console.log();
|
|
|
|
|
2023-11-30 05:38:12 +00:00
|
|
|
console.log("## Ignored Discord Errors");
|
2024-06-01 02:28:58 +00:00
|
|
|
report.ignoredErrors.forEach(e => {
|
2024-06-12 21:30:11 +00:00
|
|
|
console.log(`- ${toCodeBlock(e, "- ".length)}`);
|
2023-11-30 05:38:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
console.log();
|
|
|
|
|
2022-11-11 12:27:44 +00:00
|
|
|
if (process.env.DISCORD_WEBHOOK) {
|
|
|
|
await fetch(process.env.DISCORD_WEBHOOK, {
|
|
|
|
method: "POST",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json"
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
description: "Here's the latest Vencord Report!",
|
2022-12-20 01:59:16 +00:00
|
|
|
username: "Vencord Reporter" + (CANARY ? " (Canary)" : ""),
|
2023-12-14 00:46:51 +00:00
|
|
|
avatar_url: "https://cdn.discordapp.com/avatars/1017176847865352332/c312b6b44179ae6817de7e4b09e9c6af.webp?size=512",
|
2022-11-11 12:27:44 +00:00
|
|
|
embeds: [
|
|
|
|
{
|
|
|
|
title: "Bad Patches",
|
|
|
|
description: report.badPatches.map(p => {
|
|
|
|
const lines = [
|
|
|
|
`**__${p.plugin} (${p.type}):__**`,
|
|
|
|
`ID: \`${p.id}\``,
|
2024-06-12 21:30:11 +00:00
|
|
|
`Match: ${toCodeBlock(p.match, "Match: ".length, true)}`
|
2022-11-11 12:27:44 +00:00
|
|
|
];
|
2024-06-12 21:30:11 +00:00
|
|
|
if (p.error) lines.push(`Error: ${toCodeBlock(p.error, "Error: ".length, true)}`);
|
2022-11-11 12:27:44 +00:00
|
|
|
return lines.join("\n");
|
|
|
|
}).join("\n\n") || "None",
|
|
|
|
color: report.badPatches.length ? 0xff0000 : 0x00ff00
|
|
|
|
},
|
2023-11-25 00:32:21 +00:00
|
|
|
{
|
|
|
|
title: "Bad Webpack Finds",
|
2024-06-12 21:30:11 +00:00
|
|
|
description: report.badWebpackFinds.map(f => toCodeBlock(f, 0, true)).join("\n") || "None",
|
2023-11-25 00:32:21 +00:00
|
|
|
color: report.badWebpackFinds.length ? 0xff0000 : 0x00ff00
|
|
|
|
},
|
2022-11-11 12:27:44 +00:00
|
|
|
{
|
|
|
|
title: "Bad Starts",
|
|
|
|
description: report.badStarts.map(p => {
|
|
|
|
const lines = [
|
|
|
|
`**__${p.plugin}:__**`,
|
2024-06-12 21:30:11 +00:00
|
|
|
toCodeBlock(p.error, 0, true)
|
2022-11-11 12:27:44 +00:00
|
|
|
];
|
|
|
|
return lines.join("\n");
|
|
|
|
}
|
|
|
|
).join("\n\n") || "None",
|
|
|
|
color: report.badStarts.length ? 0xff0000 : 0x00ff00
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "Discord Errors",
|
2024-06-12 21:30:11 +00:00
|
|
|
description: report.otherErrors.length ? toCodeBlock(report.otherErrors.join("\n"), 0, true) : "None",
|
2022-11-11 12:27:44 +00:00
|
|
|
color: report.otherErrors.length ? 0xff0000 : 0x00ff00
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
}).then(res => {
|
|
|
|
if (!res.ok) console.error(`Webhook failed with status ${res.status}`);
|
|
|
|
else console.error("Posted to Discord Webhook successfully");
|
|
|
|
});
|
|
|
|
}
|
2022-11-11 11:37:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
page.on("console", async e => {
|
|
|
|
const level = e.type();
|
2023-11-25 00:32:21 +00:00
|
|
|
const rawArgs = e.args();
|
2022-11-11 11:37:37 +00:00
|
|
|
|
2024-06-01 02:28:58 +00:00
|
|
|
async function getText() {
|
|
|
|
try {
|
|
|
|
return await Promise.all(
|
|
|
|
e.args().map(async a => {
|
|
|
|
return await maybeGetError(a) || await a.jsonValue();
|
|
|
|
})
|
|
|
|
).then(a => a.join(" ").trim());
|
|
|
|
} catch {
|
|
|
|
return e.text();
|
|
|
|
}
|
2022-11-11 11:37:37 +00:00
|
|
|
}
|
|
|
|
|
2024-06-01 02:28:58 +00:00
|
|
|
const firstArg = await rawArgs[0]?.jsonValue();
|
|
|
|
|
2023-11-25 00:32:21 +00:00
|
|
|
const isVencord = firstArg === "[Vencord]";
|
|
|
|
const isDebug = firstArg === "[PUP_DEBUG]";
|
|
|
|
|
2024-06-01 02:28:58 +00:00
|
|
|
outer:
|
2023-11-25 00:32:21 +00:00
|
|
|
if (isVencord) {
|
2024-05-29 09:03:31 +00:00
|
|
|
try {
|
2024-06-01 02:28:58 +00:00
|
|
|
var args = await Promise.all(e.args().map(a => a.jsonValue()));
|
2024-05-29 09:03:31 +00:00
|
|
|
} catch {
|
2024-06-01 02:28:58 +00:00
|
|
|
break outer;
|
2024-05-29 09:03:31 +00:00
|
|
|
}
|
2022-11-11 11:37:37 +00:00
|
|
|
|
2024-06-01 02:28:58 +00:00
|
|
|
const [, tag, message, otherMessage] = args as Array<string>;
|
2022-11-11 11:37:37 +00:00
|
|
|
|
|
|
|
switch (tag) {
|
|
|
|
case "WebpackInterceptor:":
|
2023-12-14 00:41:09 +00:00
|
|
|
const patchFailMatch = message.match(/Patch by (.+?) (had no effect|errored|found no module) \(Module id is (.+?)\): (.+)/)!;
|
|
|
|
if (!patchFailMatch) break;
|
|
|
|
|
2024-06-01 02:28:58 +00:00
|
|
|
console.error(await getText());
|
2023-11-25 00:32:21 +00:00
|
|
|
process.exitCode = 1;
|
|
|
|
|
2023-12-14 00:41:09 +00:00
|
|
|
const [, plugin, type, id, regex] = patchFailMatch;
|
2022-11-11 11:37:37 +00:00
|
|
|
report.badPatches.push({
|
|
|
|
plugin,
|
|
|
|
type,
|
|
|
|
id,
|
2023-09-06 02:14:27 +00:00
|
|
|
match: regex.replace(/\[A-Za-z_\$\]\[\\w\$\]\*/g, "\\i"),
|
2024-06-01 02:28:58 +00:00
|
|
|
error: await maybeGetError(e.args()[3])
|
2022-11-11 11:37:37 +00:00
|
|
|
});
|
2023-11-25 00:32:21 +00:00
|
|
|
|
2022-11-11 11:37:37 +00:00
|
|
|
break;
|
|
|
|
case "PluginManager:":
|
2023-11-25 00:32:21 +00:00
|
|
|
const failedToStartMatch = message.match(/Failed to start (.+)/);
|
|
|
|
if (!failedToStartMatch) break;
|
|
|
|
|
2024-06-01 02:28:58 +00:00
|
|
|
console.error(await getText());
|
2023-11-25 00:32:21 +00:00
|
|
|
process.exitCode = 1;
|
|
|
|
|
|
|
|
const [, name] = failedToStartMatch;
|
2022-11-11 11:37:37 +00:00
|
|
|
report.badStarts.push({
|
|
|
|
plugin: name,
|
2024-06-01 02:28:58 +00:00
|
|
|
error: await maybeGetError(e.args()[3]) ?? "Unknown error"
|
2022-11-11 11:37:37 +00:00
|
|
|
});
|
2023-11-25 00:32:21 +00:00
|
|
|
|
2022-11-11 11:37:37 +00:00
|
|
|
break;
|
2024-06-01 20:51:50 +00:00
|
|
|
case "LazyChunkLoader:":
|
|
|
|
console.error(await getText());
|
|
|
|
|
|
|
|
switch (message) {
|
|
|
|
case "A fatal error occurred:":
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2024-06-01 21:39:01 +00:00
|
|
|
|
2022-11-11 11:37:37 +00:00
|
|
|
break;
|
2024-06-01 02:28:58 +00:00
|
|
|
case "Reporter:":
|
|
|
|
console.error(await getText());
|
2023-11-25 00:32:21 +00:00
|
|
|
|
2024-06-01 02:28:58 +00:00
|
|
|
switch (message) {
|
2024-06-01 20:51:50 +00:00
|
|
|
case "A fatal error occurred:":
|
|
|
|
process.exit(1);
|
2024-06-01 02:28:58 +00:00
|
|
|
case "Webpack Find Fail:":
|
|
|
|
process.exitCode = 1;
|
|
|
|
report.badWebpackFinds.push(otherMessage);
|
|
|
|
break;
|
|
|
|
case "Finished test":
|
|
|
|
await browser.close();
|
|
|
|
await printReport();
|
|
|
|
process.exit();
|
|
|
|
}
|
2024-05-22 03:47:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isDebug) {
|
2024-06-01 02:28:58 +00:00
|
|
|
console.error(await getText());
|
2024-05-22 03:47:12 +00:00
|
|
|
} else if (level === "error") {
|
|
|
|
const text = await getText();
|
2023-05-01 07:26:27 +00:00
|
|
|
|
2023-12-14 00:41:09 +00:00
|
|
|
if (text.length && !text.startsWith("Failed to load resource: the server responded with a status of") && !text.includes("Webpack")) {
|
2024-06-01 02:28:58 +00:00
|
|
|
if (IGNORED_DISCORD_ERRORS.some(regex => text.match(regex))) {
|
|
|
|
report.ignoredErrors.push(text);
|
|
|
|
} else {
|
|
|
|
console.error("[Unexpected Error]", text);
|
|
|
|
report.otherErrors.push(text);
|
|
|
|
}
|
2023-02-01 13:13:55 +00:00
|
|
|
}
|
2022-11-11 11:37:37 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-06-01 02:28:58 +00:00
|
|
|
page.on("error", e => console.error("[Error]", e.message));
|
2024-06-06 03:47:57 +00:00
|
|
|
page.on("pageerror", e => {
|
|
|
|
if (!e.message.startsWith("Object") && !e.message.includes("Cannot find module")) {
|
|
|
|
console.error("[Page Error]", e.message);
|
|
|
|
report.otherErrors.push(e.message);
|
|
|
|
} else {
|
|
|
|
report.ignoredErrors.push(e.message);
|
|
|
|
}
|
|
|
|
});
|
2022-11-11 11:37:37 +00:00
|
|
|
|
2024-05-30 07:44:13 +00:00
|
|
|
async function reporterRuntime(token: string) {
|
2024-06-01 02:28:58 +00:00
|
|
|
Vencord.Webpack.waitFor(
|
2024-06-01 02:47:31 +00:00
|
|
|
Vencord.Webpack.filters.byProps("loginToken"),
|
2024-06-01 02:28:58 +00:00
|
|
|
m => {
|
|
|
|
console.log("[PUP_DEBUG]", "Logging in with token...");
|
|
|
|
m.loginToken(token);
|
2024-05-22 03:47:12 +00:00
|
|
|
}
|
2024-06-01 02:28:58 +00:00
|
|
|
);
|
2022-11-11 11:37:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await page.evaluateOnNewDocument(`
|
2024-05-30 07:44:13 +00:00
|
|
|
if (location.host.endsWith("discord.com")) {
|
|
|
|
${readFileSync("./dist/browser.js", "utf-8")};
|
|
|
|
(${reporterRuntime.toString()})(${JSON.stringify(process.env.DISCORD_TOKEN)});
|
|
|
|
}
|
2022-11-11 11:37:37 +00:00
|
|
|
`);
|
|
|
|
|
2022-12-20 01:59:16 +00:00
|
|
|
await page.goto(CANARY ? "https://canary.discord.com/login" : "https://discord.com/login");
|