powercord-org / powercord

A lightweight @discord client mod focused on simplicity and performance.
MIT License
1.2k stars 147 forks source link

Not working with electron 15 due to contextIsolation issues #609

Closed LunNova closed 2 years ago

LunNova commented 2 years ago

Describe the bug When launching discord with electron 15, you get stuck on a grey screen and this error is logged.

[Powercord] Loading Powercord
node:electron/js2c/renderer_init:81 Unable to load preload script: /nix/store/b2pn5xhr81sxkvccj0v2qg3jjwzzka80-powercord/src/preload.js
(anonymous) @ node:electron/js2c/renderer_init:81
node:electron/js2c/renderer_init:81 TypeError: Cannot read properties of undefined (reading 'Element')
    at Object.<anonymous> (/nix/store/b2pn5xhr81sxkvccj0v2qg3jjwzzka80-powercord/src/fake_node_modules/powercord/util/getOwnerInstance.js:5)
    at Object.<anonymous> (/nix/store/b2pn5xhr81sxkvccj0v2qg3jjwzzka80-powercord/src/fake_node_modules/powercord/util/getOwnerInstance.js:18)
    at Module._compile (node:internal/modules/cjs/loader:1110)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1140)
    at Module.load (node:internal/modules/cjs/loader:982)
    at Module._load (node:internal/modules/cjs/loader:823)
    at Function.c._load (node:electron/js2c/asar_bundle:5)
    at Function.o._load (node:electron/js2c/renderer_init:29)
    at Module.require (node:internal/modules/cjs/loader:1006)
    at require (node:internal/modules/cjs/helpers:93)

To Reproduce nix run .#discord-plugged after removing this patch https://github.com/LunNova/nixos-configs/blob/dev/packages/powercord/default.nix#L10

Probably also reproducible on arch by trying to use powercord with https://aur.archlinux.org/packages/discord_arch_electron/ but I don't use arch so haven't tried.

Expected behavior A clear and concise description of what you expected to happen.

Desktop (please complete the following information):

        "owner": "powercord-org",
        "repo": "powercord",
        "rev": "12de9dc6c8c35cec730d134731e8cb7c282f0899",

Additional context

Add any other context about the problem here.

I was able to work around the issue with this patch, it likely causes other issues. https://github.com/LunNova/nixos-configs/blob/dev/packages/powercord/force-new-backend.js.patch

diff -ur a/ b/
--- a/src/preload.js      2021-09-27 18:51:11.900797800 -0700
+++ b/src/preload.js      2021-12-17 10:25:44.803464279 -0800
@@ -8,3 +8,3 @@
 const { webFrame } = require('electron');
-global.NEW_BACKEND = !process.versions.electron.startsWith('13') && process.contextIsolated;
+global.NEW_BACKEND = true;

 require('../polyfills');
--- a/src/browserWindow.js      2021-09-27 18:51:11.900797800 -0700
+++ b/src/browserWindow.js      2021-12-17 10:25:44.803464279 -0800
@@ -21,3 +21,4 @@
   constructor (opts) {
     let originalPreload;
+    if (!opts.webPreferences) opts.webPreferences = {};
     if (opts.webContents) {
--- a/src/browserWindow.js      2021-09-27 18:51:11.900797800 -0700
+++ b/src/browserWindow.js      2021-12-17 10:25:44.803464279 -0800
@@ -52,5 +52,6 @@
     }

+    opts.webPreferences.contextIsolation = true;
     const win = new BrowserWindow(opts);
     const ogLoadUrl = win.loadURL.bind(win);
spectrapulse commented 2 years ago

For as far as I know only the official canary builds of Discord are supported.

So I'm pretty sure this issue is invalid. But that's probably better left to the maintainer(s) to decide.

https://github.com/powercord-org/powercord#how-can-i-install-powercord-on-stable-or-ptb and #32 may be relevant

LunNova commented 2 years ago

This is with canary + electron 15.

It looked like handling electron 15 properly is desired, because other work has already been done for it eg #547

spectrapulse commented 2 years ago

This is with canary + electron 15.

It looked like handling electron 15 properly is desired, because other work has already been done for it eg #547

But that doesn't make it an official build. Current release of Canary is on Electron 13.6.6, that's not 15.

spectrapulse commented 2 years ago

It's also worth mentioning that they're currently working on v3 which will have a lot of breaking changes. The current state of the project was for as far I know maintainance only which means no futures will be added and to the looks of it only existing stuff will get fixed.

So as much as it is desireable. There's no need to support anything else than upstream builds of canary released by Discord themselves.

And I think that #463 backs up my claim. As only the official build found in the community repository is supported and not the package listed in the AUR.

cyyynthia commented 2 years ago

We only support Discord Canary, which means anything not working on versions above (and below) 13 is a non-issue, especially since recent things done by Discord which seem to imply that Electron 13 will remain in use for a while.

Getting rid of top.context was done in anticipation of Discord upgrading and due to the nature of the change which fundamentally affects how Powercord has to do things and was a large change.