aboutsummaryrefslogtreecommitdiff
path: root/src/utils/patchWebpack.ts
diff options
context:
space:
mode:
authorVendicated <vendicated@riseup.net>2022-09-15 18:17:52 +0200
committerVendicated <vendicated@riseup.net>2022-09-15 18:17:52 +0200
commit9bf28c0e7adc47173963875d526ced713efea171 (patch)
tree04b0723bc4f1e3ceebbb9ea65693c310ee88864c /src/utils/patchWebpack.ts
parentb1d3f5e52fc7592907a3a18d5bce3f3b785e4985 (diff)
downloadVencord-9bf28c0e7adc47173963875d526ced713efea171.tar.gz
Vencord-9bf28c0e7adc47173963875d526ced713efea171.tar.bz2
Vencord-9bf28c0e7adc47173963875d526ced713efea171.zip
Remove newlines in webpack chunks
Diffstat (limited to 'src/utils/patchWebpack.ts')
-rw-r--r--src/utils/patchWebpack.ts15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/utils/patchWebpack.ts b/src/utils/patchWebpack.ts
index 9ae9fbf..798dcde 100644
--- a/src/utils/patchWebpack.ts
+++ b/src/utils/patchWebpack.ts
@@ -9,11 +9,7 @@ const logger = new Logger("WebpackInterceptor", "#8caaee");
Object.defineProperty(window, WEBPACK_CHUNK, {
get: () => webpackChunk,
set: (v) => {
- // There are two possible values for push.
- // - Native push with toString result of function push() { [native code] }
- // - Webpack's push with toString result of function() { [native code] }
- // We don't want to override the native one, so check for "push"
- if (v && !v.push.toString().includes("push")) {
+ if (v?.push !== Array.prototype.push) {
logger.info(`Patching ${WEBPACK_CHUNK}.push`);
_initWebpack(v);
patchPush();
@@ -35,7 +31,14 @@ function patchPush() {
for (const id in modules) {
let mod = modules[id];
- let code = mod.toString();
+ // Discords Webpack chunks for some ungodly reason contain random
+ // newlines. Cyn recommended this workaround and it seems to work fine,
+ // however this could potentially break code, so if anything goes weird,
+ // this is probably why.
+ // Additionally, `[actual newline]` is one less char than "\n", so if Discord
+ // ever targets newer browsers, the minifier could potentially use this trick and
+ // cause issues.
+ let code = mod.toString().replaceAll("\n", "");
const originalMod = mod;
const patchedBy = new Set();