From 4c7e8cd4cb39bf62948418f62af73d3c1b930306 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Wed, 12 Aug 2026 02:01:25 +0200 Subject: [PATCH] fix Discord invite page crashing in browser version --- src/plugins/_core/noTrack.ts | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/plugins/_core/noTrack.ts b/src/plugins/_core/noTrack.ts index 6fcb4daba..5ba03b466 100644 --- a/src/plugins/_core/noTrack.ts +++ b/src/plugins/_core/noTrack.ts @@ -21,6 +21,7 @@ import { Devs } from "@utils/constants"; import { Logger } from "@utils/Logger"; import definePlugin, { OptionType, StartAt } from "@utils/types"; import { WebpackRequire } from "@vencord/discord-types/webpack"; +import { Flux, FluxDispatcher } from "@webpack/common"; const settings = definePluginSettings({ disableAnalytics: { @@ -45,7 +46,7 @@ export default definePlugin({ predicate: () => settings.store.disableAnalytics, replacement: { match: /\(0,\i\.analyticsTrackingStoreMaker\)/, - replace: "(()=>{})", + replace: "$self.analyticsTrackingStoreMaker", }, }, { @@ -140,5 +141,37 @@ export default definePlugin({ Reflect.deleteProperty(window, "DiscordSentry"); } }); + }, + + analyticsTrackingStoreMaker() { + class AnalyticsTrackingStoreStub extends Flux.Store { + static displayName = "AnalyticsTrackingStore"; + + requestDrain() { } + + async submitEventsImmediately() { + // This is supposed to return a Discord rest response but we can't know what the correct shape would be, because + // 1. It's not used anywhere + // 2. It takes a dynamic url + // Instead we throw an error with the same structure as a Discord rest error which they probably should handle gracefully. + // Discord also throws a plain object instead of Error class + + throw { + ok: false, + status: 500, + body: { + message: "Analytics tracking is disabled by NoTrack", + code: 0 + }, + headers: {}, + text: JSON.stringify({ + message: "Analytics tracking is disabled by NoTrack", + code: 0 + }) + }; + } + } + + return new AnalyticsTrackingStoreStub(FluxDispatcher); } });