-
Notifications
You must be signed in to change notification settings - Fork 15k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Desktop capturer segmentation Fault #36660
Comments
Please attach a crash dump. You can collect them by adding the following snippet to your main process code, before app.whenReady: const { app, crashReporter } = require('electron')
console.log(app.getPath('crashDumps'))
crashReporter.start({ submitURL: '', uploadToServer: false }) Then reproduce the crash, zip up the crash dumps directory and attach it here. |
Hi @nornagon, here you can find the log directory :) |
@mgonzalezg9 does That being said, for me Electron didn't segfaulted on Also, increasing the log verbosity in Electron seemed to confirm that for me it segfaulted because API was looking for X11 windows / desktops. Also the |
I think it must, because screen sharing is working perfectly in Chromium and it is the same underlying technology |
@mgonzalezg9 could you share how you run I also couldn't really find any information about PipeWire support and how that should be enabled (I'm pretty sure it won't work out-of-the-box). |
These are the contents of my [core]
# i.MX: Disable idle timeout
idle-time=0
gbm-format=argb8888
use-g2d=0
[libinput]
touchscreen_calibrator=true
[shell]
#panel-location=""
#panel-position=none**
background-image=/home/ventilator/fondoversatile1366766.png
[launcher]
icon=/home/ventilator/ib.png
path=DISPLAY=wayland-0 /usr/bin/inbentus-sav-21-frontend --no-sandbox --enable-features=UseOzonePlatform --ozone-platform=wayland The launcher icon is for the app that is causing the segmentation fault. Sorry for replying so late, I've been off for a week |
@mgonzalezg9 I've actually tested how it works on GNOME and I can confirm the mentioned issue is reproducible on |
@SpacingBat3 well the underlying problem is that my app needs to record the whole screen without prompting the user, so that's why I thought in that solution using desktopCapturer. However I thought electron would use PipeWire internally |
Is there another alternative to PipeWire that can make it work? |
@mgonzalezg9 I'm not sure there's anything standardized as portals and PipeWire across different DE's.
There are good reasons why this should not be possible on Wayland (mostly privacy concerns and overuses for malicious purposes), at least for regular user applications. Some people even mentioned that X11 was vulnerable because of how many permissions regular applications had within entire desktop.
There's nothing special here, I assume most of your issues are due to the lack of PipeWire. As of the Chromium however, I believe it could work normally when I've tested it even without PipeWire and XWayland being present, but you would be unable to record anything related to desktop or other windows (only tabs recording were available) or with XWayland and without PipeWire support, you would be limited only to X11 windows. |
Since upgrading to Electron 23, my usual workaround of disabling Downgrading to Electron 22.2.1 allows the workaround (only sharing XWayland windows via X11) to keep working. |
Hi @kris7t, I tried with Electron 22.2.1 but I am still facing the same problem. I've been searching the web but cannot find a flag to run the app with xwayland, do you know any ways of testing that? |
@mgonzalezg9 I tried Note that the application you're running might get started with any of these flags by default, and it may enable or disable feature flags at runtime. Check the launcher script or desktop entry, if any, and the source code of the application. To see whether the application is using XWayland, refer to your compositor (e.g., |
Hi. I was able to run electron on xwayland by removing environment variable.
Unfortunately, desktopCapturer is not able to capture screen properly under xwayland, shared stream is a black rectangle with cursor. The app does not crash, at least. |
@apocalyp0sys you can still share individual applications, provided they run under XWayland, too (unless your compositor does something to isolate individual XWayland client by running multiple XWayland servers, but that's rare, I think). |
FYI I've found a workaround myself for the crash, take a look at this comment: SpacingBat3/WebCord#328 (comment) Even through keeping things hard-coded doesn't seem to be the best idea, it seem to at least work to most people which set up PipeWire for screen sharing correctly. While @mgonzalezg9 suggested that it might not work for every environment, the number he got seemed to be associated to XWayland rather than PipeWire capture API. Hopefully that will help you to deal with it for now and Electron team will react (at least update the labels – there's much more information about the issue now and my tests shown that versions older than |
Hi @SpacingBat3, I tried to figure out the id so that the workaround works but wasn't able :/ Any ideas of how to find it? |
I used Electron 20/21 where You might as well take a look at my code and fetch it from there, I won't mind doing that as I think that hard-coded object will have similar or exactly the same structure to be compliant with Electron types. Take a note that you still might want to use |
I dug into this a bit on Electron main and got past the crash with this change to WebRTC's desktop_media_list_base.cc: diff --git a/chrome/browser/media/webrtc/desktop_media_list_base.cc b/chrome/browser/media/webrtc/desktop_media_list_base.cc
index 7809273017..a956f3c2dc 100644
--- a/chrome/browser/media/webrtc/desktop_media_list_base.cc
+++ b/chrome/browser/media/webrtc/desktop_media_list_base.cc
@@ -72,6 +72,11 @@ void DesktopMediaListBase::StartUpdating(DesktopMediaListObserver* observer) {
void DesktopMediaListBase::Update(UpdateCallback callback, bool refresh_thumbnails) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(sources_.empty());
+
+ // If there is a delegated source list, it may not have been started yet.
+ if (IsSourceListDelegated())
+ StartDelegatedCapturer();
+
DCHECK(!refresh_callback_);
refresh_callback_ = std::move(callback);
Refresh(refresh_thumbnails); The general problem is that Electron's DesktopCapturer does not seem to "start" the "delegated capturer" (Wayland's native capture window) before calling this Update method. "Delegated" capturers that show their own UI follow slightly different code paths than the old style of capturers, and of course Chromium does something different from DesktopCapturer. With this change I can get a toy example to show the Wayland picker and let me share the screen on Ubuntu 22.04.2 (though the picker comes up twice, possibly once each for the main and renderer processes, I didn't check). I don't think it's quite as simple as that, because sometimes when I quit I see the system still showing the "you are sharing your screen" status icon in the top right. I'm not a strong enough Pipewire, WebRTC, or Electron engineer to say whether this is the correct fix, but maybe an Electron person can now make progress here. |
Thinking about this further, it seems like |
the #37511 may fix this |
That might fix the crash (unsure), but we still eventually do need the Wayland capturer, or we'll only be able to capture a subset of the local windows. |
Fixed the issue using the app with xwayland, desktopCapturer.getSources is not crashing this way. |
As @jrose-signal said, you can only share x11 application with this so-called "fix" @mgonzalezg9 As the use case is clearly the screen sharing of a wayland environment, I'm not sure one can consider the problem as fixed because one can share the few old apps not supporting wayland (purpose of xwayland). What about the patch in #36660 (comment) ? Is it a realistic fix or a workaround ? |
@gza As of workaround that doesn't require patching Electron, this is what I've been doing myself for quite a long time when my app detects Wayland environment and PipeWire capturer flag used: // Workaround #328: Segfault on `desktopCapturer.getSources()` since Electron 22
}) : Promise.resolve([{
id: "screen:1:0",
appIcon: nativeImage.createEmpty(),
display_id: "",
name: "Entire Screen",
thumbnail: nativeImage.createEmpty()
} satisfies Electron.DesktopCapturerSource]); Somehow, hard-coding a source this way to avoid using I've also didn't test if |
Preflight Checklist
Electron Version
19.0.17
What operating system are you using?
Ubuntu
Operating System Version
Weston wayland
What arch are you using?
arm64 (including Apple Silicon)
Last Known Working Electron version
No response
Expected Behavior
In the file background.ts (main process) I am calling desktopCapturer to retrieve the screen id:
Actual Behavior
However when this line is invoked it prints Segmentation fault and the program crashes. I believe the problem may be related to the types array because when I set it empty it works without problems.
Testcase Gist URL
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: