Getting Discord Running On Electron 20

Small write-up about getting Discord running with Electron 20.


Discord is built with their fork of Electron 13, which is now end of life and the last version for 13.x.y is 7 months old. I recently got Discord running on Electron 20 (latest) standalone, opening it normally and having the same experience as normal. This is a small writeup as to how and what patches had to be done. Some of this references Windows binaries/etc but this is universal. (Disclaimer: I do not work for/at Discord, just modding it.)

Using our own Electron

For replacing Discord’s Electron, I wanted to have it easy and generic, which meant not using any builder and just replacing Discord’s files with the files from an Electron release. It is pretty easy to just replace the files with Electron’s. However, there will likely be various major issues if you’re using 64-bit Electron on Windows. Discord’s build for Windows is built 32-bit, so their native libraries are also 32-bit and won’t work with 64-bit Electron builds. You have to use 32-bit Electron on Windows to get most functionality. Now we just have to deal with newer Electron versions.

Electron >=17

Discord’s own app.asar fails with Electron >=17 due to this “bug” (intended behavior which was removed without notice). In my own app.asar alternative I work around this by completely replacing code which uses Module.globalPaths with require to resolve it myself seen here:

// Custom requireNative as Electron >=17 breaks Module.globalPaths for some reason
// For Updater v2: get direct path in globalPaths (first in globals)
// For Module Updater: get root path for all modules in globalPaths

const globals = require('module').globalPaths;
const { join } = require('path');

module.exports = (name, extension = '') => require(join(globals.reverse().find(x => x.includes(name)) ?? globals[0], name, extension));

Electron >=20

In Electron >=20 sandbox is enabled by default in Discord’s BrowserWindows which breaks their preloads. To resolve this we can patch the discord_desktop_core module to disable the sandbox if nodeIntegration is also disabled, like this:

for (const x of [ 'app/mainScreen.js', 'app/notificationScreen.js', 'app/popoutWindows.js' ]) {
  let content = fs.readFileSync(x, 'utf8');

  content = content.replaceAll('nodeIntegration: false,', 'nodeIntegration: false, sandbox: false,');

  fs.writeFileSync(x, content);

Discord runs on Electron 20!

And now Discord runs with the latest Electron, 20.0.0. This will be much, much easier and automatic in future with my upcoming Mu project, a custom updater server and client for OpenAsar built for small (1.5-5x smaller) downloads and easy modding.

Screenshot showing Electron 20