2022-10-22 01:17:06 +02:00
|
|
|
/*
|
|
|
|
|
* Vencord, a modification for Discord's desktop app
|
|
|
|
|
* Copyright (c) 2022 Vendicated and contributors
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2024-05-02 00:36:37 -03:00
|
|
|
import { definePluginSettings } from "@api/Settings";
|
2022-11-28 13:37:55 +01:00
|
|
|
import { Devs } from "@utils/constants";
|
2024-06-28 18:17:38 -03:00
|
|
|
import { Logger } from "@utils/Logger";
|
2024-06-28 00:53:09 -03:00
|
|
|
import definePlugin, { OptionType, StartAt } from "@utils/types";
|
2025-07-10 00:38:39 +02:00
|
|
|
import { WebpackRequire } from "@vencord/discord-types/webpack";
|
2026-08-12 02:01:25 +02:00
|
|
|
import { Flux, FluxDispatcher } from "@webpack/common";
|
2024-06-27 23:58:01 -03:00
|
|
|
|
2024-05-02 00:36:37 -03:00
|
|
|
const settings = definePluginSettings({
|
|
|
|
|
disableAnalytics: {
|
|
|
|
|
type: OptionType.BOOLEAN,
|
|
|
|
|
description: "Disable Discord's tracking (analytics/'science')",
|
|
|
|
|
default: true,
|
|
|
|
|
restartNeeded: true
|
2026-09-23 20:31:46 -04:00
|
|
|
},
|
|
|
|
|
disableStackDumping: {
|
|
|
|
|
type: OptionType.BOOLEAN,
|
|
|
|
|
description: "Print a native stack trace to the console when Discord crashes. Requires full restart.",
|
|
|
|
|
default: false,
|
|
|
|
|
restartNeeded: true,
|
|
|
|
|
target: "DESKTOP"
|
2024-05-02 00:36:37 -03:00
|
|
|
}
|
|
|
|
|
});
|
2022-08-29 22:05:22 +02:00
|
|
|
|
|
|
|
|
export default definePlugin({
|
|
|
|
|
name: "NoTrack",
|
2024-05-02 00:36:37 -03:00
|
|
|
description: "Disable Discord's tracking (analytics/'science'), metrics and Sentry crash reporting",
|
2023-08-10 15:17:29 -07:00
|
|
|
authors: [Devs.Cyn, Devs.Ven, Devs.Nuckyz, Devs.Arrow],
|
2026-07-09 20:25:37 -04:00
|
|
|
tags: ["Utility"],
|
2022-08-31 04:07:16 +02:00
|
|
|
required: true,
|
2024-05-02 00:36:37 -03:00
|
|
|
|
|
|
|
|
settings,
|
|
|
|
|
|
2023-10-25 14:56:20 +02:00
|
|
|
patches: [
|
2022-09-01 21:27:32 -06:00
|
|
|
{
|
2023-10-25 14:56:20 +02:00
|
|
|
find: "AnalyticsActionHandlers.handle",
|
2024-05-02 00:36:37 -03:00
|
|
|
predicate: () => settings.store.disableAnalytics,
|
2022-09-01 21:27:32 -06:00
|
|
|
replacement: {
|
2026-04-30 21:34:11 -04:00
|
|
|
match: /\(0,\i\.analyticsTrackingStoreMaker\)/,
|
2026-08-12 02:01:25 +02:00
|
|
|
replace: "$self.analyticsTrackingStoreMaker",
|
2022-09-01 21:27:32 -06:00
|
|
|
},
|
|
|
|
|
},
|
2023-03-06 18:54:01 -03:00
|
|
|
{
|
2025-11-02 12:28:53 -05:00
|
|
|
find: ".METRICS_V2",
|
2023-03-06 18:54:01 -03:00
|
|
|
replacement: [
|
|
|
|
|
{
|
2023-10-25 14:56:20 +02:00
|
|
|
match: /this\._intervalId=/,
|
2024-05-02 00:36:37 -03:00
|
|
|
replace: "this._intervalId=void 0&&"
|
2023-03-06 18:54:01 -03:00
|
|
|
},
|
|
|
|
|
{
|
2024-05-02 00:36:37 -03:00
|
|
|
match: /(?:increment|distribution)\(\i(?:,\i)?\){/g,
|
|
|
|
|
replace: "$&return;"
|
2023-03-06 18:54:01 -03:00
|
|
|
}
|
|
|
|
|
]
|
2024-12-14 02:36:16 -03:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
find: ".BetterDiscord||null!=",
|
|
|
|
|
replacement: {
|
|
|
|
|
// Make hasClientMods return false
|
|
|
|
|
match: /(?=let \i=window;)/,
|
|
|
|
|
replace: "return false;"
|
|
|
|
|
}
|
2024-11-08 06:54:09 -03:00
|
|
|
}
|
2024-06-28 00:53:09 -03:00
|
|
|
],
|
|
|
|
|
|
2025-09-23 22:24:58 +02:00
|
|
|
// The TRACK event takes an optional `resolve` property that is called when the tracking event was submitted to the server.
|
|
|
|
|
// A few spots in Discord await this callback before continuing (most notably the Voice Debug Logging toggle).
|
|
|
|
|
// Since we NOOP the AnalyticsActionHandlers module, there is no handler for the TRACK event, so we have to handle it ourselves
|
|
|
|
|
flux: {
|
|
|
|
|
TRACK(event) {
|
|
|
|
|
event?.resolve?.();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2024-06-28 00:53:09 -03:00
|
|
|
startAt: StartAt.Init,
|
|
|
|
|
start() {
|
2024-06-28 18:17:38 -03:00
|
|
|
// Sentry is initialized in its own WebpackInstance.
|
|
|
|
|
// It has everything it needs preloaded, so, it doesn't include any chunk loading functionality.
|
|
|
|
|
// Because of that, its WebpackInstance doesnt export wreq.m or wreq.c
|
|
|
|
|
|
2026-04-23 04:27:58 +02:00
|
|
|
// To circuvent this and disable Sentry we are gonna hook when wreq.d of its WebpackInstance is set.
|
2024-06-29 01:26:03 -03:00
|
|
|
// When that happens we are gonna forcefully throw an error and abort everything.
|
2026-04-23 04:27:58 +02:00
|
|
|
Object.defineProperty(Function.prototype, "d", {
|
2024-06-28 18:17:38 -03:00
|
|
|
configurable: true,
|
|
|
|
|
|
2026-04-23 04:27:58 +02:00
|
|
|
set(this: WebpackRequire, esmDeclareFunc: WebpackRequire["d"]) {
|
|
|
|
|
Object.defineProperty(this, "d", {
|
|
|
|
|
value: esmDeclareFunc,
|
2024-06-28 18:17:38 -03:00
|
|
|
configurable: true,
|
|
|
|
|
enumerable: true,
|
|
|
|
|
writable: true
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Ensure this is most likely the Sentry WebpackInstance.
|
|
|
|
|
// Function.g is a very generic property and is not uncommon for another WebpackInstance (or even a React component: <g></g>) to include it
|
|
|
|
|
const { stack } = new Error();
|
2025-02-07 20:07:17 -03:00
|
|
|
if (this.c != null || !stack?.includes("http") || !String(this).includes("exports:{}")) {
|
2024-06-28 18:17:38 -03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-07 20:07:17 -03:00
|
|
|
const assetPath = stack.match(/http.+?(?=:\d+?:\d+?$)/m)?.[0];
|
2024-06-29 01:26:03 -03:00
|
|
|
if (!assetPath) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-06-28 18:17:38 -03:00
|
|
|
|
2024-06-29 01:26:03 -03:00
|
|
|
const srcRequest = new XMLHttpRequest();
|
|
|
|
|
srcRequest.open("GET", assetPath, false);
|
|
|
|
|
srcRequest.send();
|
2024-06-28 18:17:38 -03:00
|
|
|
|
2024-06-29 01:26:03 -03:00
|
|
|
// Final condition to see if this is the Sentry WebpackInstance
|
2025-02-07 20:07:17 -03:00
|
|
|
// This is matching window.DiscordSentry=, but without `window` to avoid issues on some proxies
|
|
|
|
|
if (!srcRequest.responseText.includes(".DiscordSentry=")) {
|
2024-06-29 01:26:03 -03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
new Logger("NoTrack", "#8caaee").info("Disabling Sentry by erroring its WebpackInstance");
|
|
|
|
|
|
2026-04-23 04:27:58 +02:00
|
|
|
Reflect.deleteProperty(Function.prototype, "d");
|
2024-06-29 01:26:03 -03:00
|
|
|
Reflect.deleteProperty(window, "DiscordSentry");
|
|
|
|
|
|
|
|
|
|
throw new Error("Sentry successfully disabled");
|
2024-06-28 18:17:38 -03:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2024-06-28 00:53:09 -03:00
|
|
|
Object.defineProperty(window, "DiscordSentry", {
|
|
|
|
|
configurable: true,
|
2024-06-28 18:17:38 -03:00
|
|
|
|
2024-06-28 00:53:09 -03:00
|
|
|
set() {
|
2024-06-28 18:17:38 -03:00
|
|
|
new Logger("NoTrack", "#8caaee").error("Failed to disable Sentry. Falling back to deleting window.DiscordSentry");
|
2024-06-29 01:26:03 -03:00
|
|
|
|
2026-04-23 04:27:58 +02:00
|
|
|
Reflect.deleteProperty(Function.prototype, "d");
|
2024-06-28 00:53:09 -03:00
|
|
|
Reflect.deleteProperty(window, "DiscordSentry");
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-08-12 02:01:25 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
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);
|
2024-06-28 00:53:09 -03:00
|
|
|
}
|
2022-09-01 21:27:32 -06:00
|
|
|
});
|