fix Discord invite page crashing in browser version

This commit is contained in:
Vendicated 2026-08-12 02:01:25 +02:00
parent 2f786a2ee5
commit 4c7e8cd4cb
No known key found for this signature in database
GPG key ID: D66986BAF75ECF18

View file

@ -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);
}
});