-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[antitrack] fix sentry and add metrics blocking
- Loading branch information
1 parent
f961288
commit dbb0c6b
Showing
1 changed file
with
47 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,52 @@ | ||
const { scoped } = shelter.plugin; | ||
const { | ||
plugin: { scoped }, | ||
util: { log }, | ||
} = shelter; | ||
|
||
// apply openasar's sentry removers | ||
// https://github.com/GooseMod/OpenAsar/blob/7a04cb57dff43f328de78addc234e9d21ff079a8/src/mainWindow.js#L3 | ||
// Disable Sentry as soon as possible | ||
try { | ||
window.__SENTRY__.hub.getClient().getOptions().enabled = false; | ||
Object.keys(console).forEach( | ||
(x) => (console[x] = console[x].__sentry_original__ ?? console[x]), | ||
); | ||
} catch {} | ||
if (DiscordSentry) { | ||
DiscordSentry.close(); | ||
} else { | ||
Object.defineProperty(window, "DiscordSentry", { | ||
set(v) { | ||
delete window.DiscordSentry; | ||
window.DiscordSentry = v; | ||
setTimeout(v.close); | ||
}, | ||
enumerable: false, | ||
configurable: true, | ||
}); | ||
} | ||
} catch (e) { | ||
log(`[Antitrack] Error while disabling Sentry ${e}`); | ||
} | ||
|
||
// stop TRACK dispatches from causing science etc requests | ||
// this is not done via flux.intercept() so that plugins can still listen for these dispatches | ||
// Unpatch console functions | ||
try { | ||
Object.keys(console).forEach((func) => { | ||
const original = console[func]?.__sentry_original__; | ||
if (!original) return; | ||
console[func] = original; | ||
}); | ||
} catch (e) { | ||
log(`[Antitrack] Error while unpatching console functions ${e}`); | ||
} | ||
|
||
// Stop TRACK dispatches from causing science requests | ||
// This is not done via flux.intercept() so that plugins can still listen for these dispatches | ||
// as TRACK dispatches are *insanely useful* | ||
scoped.http.intercept("POST", /^\/science/, () => {}); | ||
|
||
// Block metrics requests separately, as they're not sent via the http module | ||
// Just in case we also account for subdomains/release channels | ||
const metricsRe = | ||
/^https?:\/\/([a-z0-9\-]+\.)?discord\.com\/api\/v\d+\/metrics/; | ||
const getSentryProp = (obj) => | ||
obj[Object.keys(obj).find((k) => k.startsWith("__sentry_xhr"))]; | ||
|
||
scoped.http.intercept("POST", /^\/science|^\/error-reporting-proxy/, () => {}); | ||
scoped.patcher.instead("send", XMLHttpRequest.prototype, function (args, orig) { | ||
const url = getSentryProp(this)?.url; | ||
if (typeof url === "string" && metricsRe.test(url)) return; | ||
return orig.apply(this, args); | ||
}); |