fix webpack patching

This commit is contained in:
Vendicated 2023-10-25 14:26:10 +02:00 committed by V
parent 97c0face2f
commit 4e27722b54
2 changed files with 25 additions and 13 deletions

View file

@ -24,7 +24,7 @@ export default definePlugin({
description: "Disable Discord's tracking ('science'), metrics and Sentry crash reporting",
authors: [Devs.Cyn, Devs.Ven, Devs.Nuckyz, Devs.Arrow],
required: true,
patches: [
patches: true ? [] : [
{
find: "TRACKING_URL:",
replacement: {

View file

@ -31,25 +31,31 @@ const logger = new Logger("WebpackInterceptor", "#8caaee");
if (window[WEBPACK_CHUNK]) {
logger.info(`Patching ${WEBPACK_CHUNK}.push (was already existant, likely from cache!)`);
_initWebpack(window[WEBPACK_CHUNK]);
patchPush();
patchPush(window[WEBPACK_CHUNK]);
} else {
Object.defineProperty(window, WEBPACK_CHUNK, {
get: () => webpackChunk,
set: v => {
if (v?.push !== Array.prototype.push && _initWebpack(v)) {
if (v?.push) {
if (!v.push.$$vencordOriginal) {
logger.info(`Patching ${WEBPACK_CHUNK}.push`);
patchPush();
patchPush(v);
}
if (_initWebpack(v)) {
logger.info("Successfully initialised Vencord webpack");
// @ts-ignore
delete window[WEBPACK_CHUNK];
window[WEBPACK_CHUNK] = v;
}
}
webpackChunk = v;
},
configurable: true
});
}
function patchPush() {
function patchPush(webpackGlobal: any) {
function handlePush(chunk: any) {
try {
const modules = chunk[1];
@ -213,13 +219,19 @@ function patchPush() {
logger.error("Error in handlePush", err);
}
return handlePush.original.call(window[WEBPACK_CHUNK], chunk);
return handlePush.$$vencordOriginal.call(webpackGlobal, chunk);
}
handlePush.original = window[WEBPACK_CHUNK].push;
Object.defineProperty(window[WEBPACK_CHUNK], "push", {
handlePush.$$vencordOriginal = webpackGlobal.push;
Object.defineProperty(webpackGlobal, "push", {
get: () => handlePush,
set: v => (handlePush.original = v),
set(v) {
Object.defineProperty(this, "push", {
value: v,
configurable: true
});
patchPush(this);
},
configurable: true
});
}