Merge branch 'dev' into modules-proxy-patches

This commit is contained in:
Nuckyz 2024-06-28 18:43:03 -03:00
commit c2d708a621
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9
6 changed files with 63 additions and 3 deletions

View file

@ -1,7 +1,7 @@
{
"name": "vencord",
"private": "true",
"version": "1.9.2",
"version": "1.9.3",
"description": "The cutest Discord client mod",
"homepage": "https://github.com/Vendicated/Vencord#readme",
"bugs": {

View file

@ -289,6 +289,8 @@ 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;
if (!e.message.startsWith("Object") && !e.message.includes("Cannot find module")) {
console.error("[Page Error]", e.message);
report.otherErrors.push(e.message);

View file

@ -18,6 +18,7 @@
import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants";
import { Logger } from "@utils/Logger";
import definePlugin, { OptionType, StartAt } from "@utils/types";
const settings = definePluginSettings({
@ -71,9 +72,64 @@ export default definePlugin({
startAt: StartAt.Init,
start() {
// Sentry is initialized in its own WebpackInstance.
// It has everything it needs preloaded, so, it doesn't include any chunk loading functionality.
// Because of that, its WebpackInstance doesnt export wreq.m or wreq.c
// To circuvent this and disable Sentry we are gonna hook when wreq.g of its WebpackInstance is set.
// When that happens we are gonna obtain a reference to its internal module cache (wreq.c) and proxy its prototype,
// so, when the first require to initialize the Sentry is attempted, we are gonna forcefully throw an error and abort everything.
Object.defineProperty(Function.prototype, "g", {
configurable: true,
set(v: any) {
Object.defineProperty(this, "g", {
value: v,
configurable: true,
enumerable: true,
writable: true
});
// Ensure this is most likely the Sentry WebpackInstance.
// Function.g is a very generic property and is not uncommon for another WebpackInstance (or even a React component: <g></g>) to include it
const { stack } = new Error();
if (!(stack?.includes("discord.com") || stack?.includes("discordapp.com")) || this.c != null || !String(this).includes("exports:{}")) {
return;
}
const cacheExtractSym = Symbol("vencord.cacheExtract");
Object.defineProperty(Object.prototype, cacheExtractSym, {
configurable: true,
get() {
// One more condition to check if this is the Sentry WebpackInstance
if (Array.isArray(this)) {
return { exports: {} };
}
new Logger("NoTrack", "#8caaee").info("Disabling Sentry by proxying its WebpackInstance cache");
Object.setPrototypeOf(this, new Proxy(this, {
get() {
throw new Error("Sentry successfully disabled");
}
}));
Reflect.deleteProperty(Object.prototype, cacheExtractSym);
Reflect.deleteProperty(window, "DiscordSentry");
return { exports: {} };
}
});
// WebpackRequire our fake module id
this(cacheExtractSym);
}
});
Object.defineProperty(window, "DiscordSentry", {
configurable: true,
set() {
new Logger("NoTrack", "#8caaee").error("Failed to disable Sentry. Falling back to deleting window.DiscordSentry");
Reflect.deleteProperty(window, "DiscordSentry");
}
});

View file

@ -87,7 +87,7 @@ export default definePlugin({
}
},
{
find: ".VIEW_FULL_PROFILE,",
find: ".BITE_SIZE,user:",
replacement: {
match: /(?<=\.BITE_SIZE,children:\[)\(0,\i\.jsx\)\(\i\.\i,\{user:(\i),/,
replace: "$self.BiteSizeReviewsButton({user:$1}),$&"

View file

@ -77,7 +77,7 @@ const settings = definePluginSettings({
});
function stringToRegex(str: string) {
const match = str.match(/^(\/)?(.+?)(?:\/([gimsuy]*))?$/); // Regex to match regex
const match = str.match(/^(\/)?(.+?)(?:\/([gimsuyv]*))?$/); // Regex to match regex
return match
? new RegExp(
match[2], // Pattern

View file

@ -45,6 +45,8 @@ define(Function.prototype, "m", {
set(this: AnyWebpackRequire, originalModules: AnyWebpackRequire["m"]) {
define(this, "m", { value: originalModules });
// We may also catch Discord bundled libs, React Devtools or other extensions WebpackInstance here.
// This ensures we actually got the right ones
const { stack } = new Error();
if (!(stack?.includes("discord.com") || stack?.includes("discordapp.com")) || Array.isArray(originalModules)) {
return;