Repository: electron
Issue: [Bug]: Redundant app-created screen share dialog on Linux Wayland
Labels: platform/linux,bug :beetle:,13-x-y,14-x-y,15-x-y,wayland

### Preflight Checklist

- [X] I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/master/CONTRIBUTING.md) for this project.
- [X] I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/master/CODE_OF_CONDUCT.md) that this project adheres to.
- [X] I have searched the [issue tracker](https://www.github.com/electron/electron/issues) for a feature request that matches the one I want to file, without success.

### Electron Version

Any version supporting PipeWire (Electron 13 works, used in Element, Jitsi Meet Electron, and Slack).

### What operating system are you using?

Any Linux on Wayland

### Expected Behavior

On Linux Wayland clicking a screen share button should immediately lead the user to the PipeWire/XDG Desktop Portal dialog (provided by operating system). This is the ideal way for apps to request to view the screen in a sandboxed Linux environment.

### Actual Behavior

On Linux Wayland sessions Electron apps show an uncessary dialog when screen sharing, that causes extra clicks and confusion. 

See what Element and Jitsi Meet Electron look like currently on Wayland: 

[!(Element Wayland PipeWire Screen Sharing)](https://user-images.githubusercontent.com/38842733/130304705-7254dc26-0467-4649-8bbd-e5e8094f2aa4.mp4)

[!(Jitsi Wayland PipeWire Screen Sharing)](https://user-images.githubusercontent.com/38842733/130304800-a6903504-2822-4cb6-8f1b-20ea6442f3d1.mp4)

When on Wayland sessions, Electron apps should skip showing the app-created dialog, and simply immediately call the PipeWire/portal prompt.

To recap for Element:

Current steps (shown in first video):
1. Click circular share button in video meeting box.
2. Click image box with missing preview.
3. Click rectangular share button.
4. Select display or window in operating system provided dialog.

Proposed steps for Linux Wayland users:
1. Click circular share button in video meeting box.
2. Select display or window in operating system provided dialog.

### Additional Information

The Wayland security model means apps cannot assume they can view any displays or windows. That is why the dialog is not able to show a picture preview properly. Even if the picture could be fixed, the dialog is still not particularly beneficial to Wayland users and should not be shown.

This likely is best fixed in Electron and not elsewhere. Three Electron apps, [Element](https://github.com/vector-im/element-desktop/issues/853), [Jitsi Meet Electron](https://github.com/jitsi/jitsi-meet-electron/issues/608), and [Slack](https://github.com/flathub/com.slack.Slack/issues/144) are known to have this redundant dialog issue. However, in Chromium the issue is different as Chromium itself manages the dialog--the app is not able to choose how it looks unlike in Electron (see above, Jitsi and Element's dialog looked different). Also, unlike Electron Chromium needs tab sharing as well, where in Electron tab sharing doesn't exist. So Electron can provide easier screen sharing functionality without losing anything, simply by avoiding letting apps create a redundant dialog when on Wayland.

There are some issue with apps like [Teams](https://github.com/electron/electron/issues/23063), [Discord](https://github.com/flathub/com.discordapp.Discord/issues/89), [Skype](https://github.com/flathub/com.skype.Client/issues/142), [Signal](https://github.com/signalapp/Signal-Desktop/issues/5350) and potentially other Electron apps with using PipeWire to screen share on Wayland. Their issues are out of scope for this issue--removing the unecessary dialog is a valid improvement that will help Electron apps that can already mostly screen share on Wayland properly. Fixing the broken apps is a seperate problem (and is most likely due to using unsupported Electron versions or non-standard WebRTC implementations).

To enable PipeWire screen sharing on Wayland in Electron or Chromium you might need to pass `--enable-features=WebRTCPipeWireCapturer` at runtime. Both [Element](https://github.com/vector-im/element-web/issues/18607) and [Jitsi](https://github.com/jitsi/jitsi-meet-electron/pull/584) (in videos above) enable this flag at build-time. This was done primarily as the experience with the flag (even with this dialog issue) is far better than without it. Without the flag Electron or Chromium will have mostly broken and unusable screen sharing functionality on Wayland.

Note this issue is not related to [Wayland support in Electron](https://github.com/electron/electron/issues/10915) in general, this is just about fixing the screen sharing dialog. Electron can be running in xwayland or Wayland and the issue will be the same.