add crash handler hijack

This commit is contained in:
Astra 2018-04-27 20:23:51 -04:00
parent ef1d47dde7
commit 8780641777

View file

@ -73,8 +73,43 @@
// post-init payload // post-init payload
document.addEventListener('ep-ready', () => { document.addEventListener('ep-ready', () => {
// hijack the crash handler
// TODO: make this less ugly
$api.util.findFuncExports('CRASH', 'prototype').prototype.render = function () {
console.error('*** DISCORD CRASH!!! ***\nLOCKING DISPATCH AND HIJACKING PAGE');
// disable dispatch(), essentially freezing react
$api.internal.dispatcher.default.dispatch = () => { };
// clear css
$("link[rel='stylesheet']").remove();
$$("style").forEach(x => x.remove());
// add a simple style to the body
$('body').style.color = '#fff';
$('body').style.backgroundColor = '#000082';
$('body').style.fontFamily = 'monospace';
// write our message to app-mount
$('#app-mount').innerHTML = `<h1>EndPwn: Discord Fatal Error</h1>
<h3>
Something has gone very, very wrong, and Discord has crashed.<br><br>
If this is the first time you've seen this error screen, press Ctrl+R and hope for the best. If this screen appears again, follow these steps:<br><br>
Try removing any new plugins and restarting again. If this solves the problem there may be a bug in the plugin.<br><br>
If problems continue, it's likely that there is a bug in EndPwn or Discord. <a href="https://discord.gg/wXdPNf2" target="_blank" style="color:#0ff">Join the EndPwn Discord server</a> for assistance.<br><br>
Details may be available in the console (Ctrl+Shift+I), but at this level of crash we can't be certain.
</h3>
<button onclick="electron.getCurrentWindow().reload()">Reload</button>
<button onclick="$api.localStorage.set('safemode',1);electron.getCurrentWindow().reload()">Reload in safe mode</button>`;
// crash whatever was calling render()
throw 'render abort';
}
// disable analytics // disable analytics
$api.util.findFuncExports("AnalyticEventConfigs").default.track = () => {}; $api.util.findFuncExports("AnalyticEventConfigs").default.track = () => { };
// enable experiments // enable experiments
$api.util.findFuncExports('isDeveloper').__defineGetter__('isDeveloper', () => true); $api.util.findFuncExports('isDeveloper').__defineGetter__('isDeveloper', () => true);