fix webpack patching

main
Vendicated 1 year ago committed by V
parent 97c0face2f
commit 4e27722b54

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

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

Loading…
Cancel
Save