Skip to content

Wrong web browser opened when clicking links #45129

Closed

Description

@NobodysNightmare

Preflight Checklist

Electron Version

33.3.0

What operating system(s) are you using?

Ubuntu

Operating System Version

24.04

What arch are you using?

x64

Last Known Working Electron version

No response

Expected Behavior

Links open in the configured default browser

Actual Behavior

Links open in Chrome/Chromium instead, regardless of the configured default browser

Testcase Gist URL

https://gist.github.com/Viicos/d77af018be1b7b27294a74c378731992

Additional Information

This is a re-open of #42611 (by @bittylicious) after @Viicos was so kind to add a repro gist (adding a gist was an absolute requirement by the Electron team on the original issue).

The original issue already well pointed out that this issue seems to be new with Ubuntu 24 and wasn't present on 22.

Workarounds presented in in the original issue:

  • Uninstalling all chrome/chromium (then e.g. a firefox will be correctly opened)
  • Adding the following to ~/.local/share/applications/mimeapps.list
[Default Applications]
x-scheme-handler/http=firefox_firefox.desktop
x-scheme-handler/https=firefox_firefox.desktop

There are some additional details available in the original issue.

Activity

  1. added
    has-repro-gist
    on Jan 6, 2025
  2. moved this to 👀 Unsorted Items in 33-x-yon Jan 6, 2025
  3. moved this to 👀 Unsorted Items in 34-x-yon Jan 6, 2025
  4. mlaurencin commented on Jan 6, 2025

    @mlaurencin
    Member

    As I mentioned in the closed issue, the provided gist produced the expected behavior on Windows, so this is most likely a Linux only issue.

  5. t3chguy commented on Jan 6, 2025

    @t3chguy
  6. Viicos commented on Jan 6, 2025

    @Viicos

    what made an inability to repro in Windows appropriate to close the issue?

    This wasn't the reason the original issue was closed, but rather because it was missing a simple reproducible example (as mentioned here).

  7. bittylicious commented on Jan 6, 2025

    @bittylicious

    Thank you for doing this @NobodysNightmare @Viicos .

    This is just a grumbling response as it would have affected everybody who uses Firefox as their default browser, on the latest stable Ubuntu, yet the original issue was closed even though it is easy to reproduce. This must affect thousands of people and likely lose Firefox a lot of "default browser" settings, which sucks when Chrome has such market share.

  8. moved this from 👀 Unsorted Items to 👍 Does Not Block Stable in 34-x-yon Jan 8, 2025
  9. geoffreybr commented on Jan 11, 2025

    @geoffreybr

    I faced the same with web links but also when opening PDF files from the desktop client of @tutao based on Electron. The PDF files were opened by calibre (ebook reader) instead of evince pdf reader whereas evince is set as the default pdf reader...

    Same workaround, adding this to ~/.local/share/applications/mimeapps.list:

    application/pdf=org.gnome.Evince.desktop
    application/x-bzpdf=org.gnome.Evince.desktop
    application/x-ext-pdf=org.gnome.Evince.desktop
    application/x-gzpdf=org.gnome.Evince.desktop
    application/x-xzpdf=org.gnome.Evince.desktop
    

    If someone face the same issue with other files, you can look in /usr/share/applications/gnome-mimeapps.list for references with mime types.

    Clicking on links has the expected behavior on other apps which are not based on Electron (pdf reader, other e-mail clients, text editor, etc.) so it looks related to Electron and not Ubuntu.

  10. esimkowitz commented on Jan 16, 2025

    @esimkowitz
    Contributor

    I did some digging into this, I believe the cause for this is that Electron sets the XDG_CURRENT_DESKTOP environment variable to Unity for Linux systems. They preserve the original value in ORIGINAL_XDG_CURRENT_DESKTOP. I've tested and confirmed that restoring the original value before calling electron.shell.openExternal makes it honor the system defaults.

    This gets a very brief callout in the Electron docs. They claim this is to improve Chromium compatibility and I have no reason to doubt that, but it seems like a bug/unexpected behavior for electron.shell.openExternal and electron.shell.openPath to not honor the original value.

  11. esimkowitz commented on Jan 21, 2025

    @esimkowitz
    Contributor

    I'm admittedly a noob in the Electron codebase and it's been forever since I've touched C++, but it seems like the overridden XDG_CURRENT_DESKTOP env var is used elsewhere in Chromium so it needs to be preserved, but shell/common/platform_util_linux.cc is not dependent on it. It seems like the XDGUtil function in shell/common/platform_util_linux.cc is the right place to correct this, as it seems like all the functions that call this are ones that should honor the system default. I think the following should work for overriding the original value, but I'm curious to get input from an Electron maintainer. @mlaurencin @clavin

    diff --git a/shell/common/platform_util_linux.cc b/shell/common/platform_util_linux.cc
    index 125b4d037a..0efd462e06 100644
    --- a/shell/common/platform_util_linux.cc
    +++ b/shell/common/platform_util_linux.cc
    @@ -58,6 +58,9 @@ const char kFreedesktopPortalName[] = "org.freedesktop.portal.Desktop";
     const char kFreedesktopPortalPath[] = "/org/freedesktop/portal/desktop";
     const char kFreedesktopPortalOpenURI[] = "org.freedesktop.portal.OpenURI";
     
    +const char kXdgCurrentDesktopEnvVar[] = "XDG_CURRENT_DESKTOP";
    +const char kOriginalXdgCurrentDesktopEnvVar[] = "ORIGINAL_XDG_CURRENT_DESKTOP";
    +
     const char kMethodOpenDirectory[] = "OpenDirectory";
     
     class ShowItemHelper {
    @@ -282,6 +285,11 @@ bool XDGUtil(const std::vector<std::string>& argv,
         base::nix::CreateLaunchOptionsWithXdgActivation(base::BindOnce(
             [](base::RepeatingClosure quit_loop, base::LaunchOptions* options_out,
                base::LaunchOptions options) {
    +          if (options.environment.find(kOriginalXdgCurrentDesktopEnvVar) !=
    +              options.environment.end()) {
    +              options.environment[kXdgCurrentDesktopEnvVar] =
    +                options.environment[kOriginalXdgCurrentDesktopEnvVar];
    +          }
               *options_out = std::move(options);
               std::move(quit_loop).Run();
             },
  12. electron-issue-triage commented on Apr 22, 2025

    @electron-issue-triage

    This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

  13. NobodysNightmare commented on Apr 22, 2025

    @NobodysNightmare
    Author

    Hello electron bot, thanks for trying to be helpful. The associated PR to this issue still has recent activity (4 days ago) and the problem still exists.

  14. charlag commented on Sep 25, 2025

    @charlag

    Hi, it doesn't look like the fix works for us:
    tutao/tutanota#9696

    When we run shell.openPath it doesn't use the default app under Ubuntu 24.04 w/ GNOME, we have the same situation on multiple machines.

    We have tried manually replacing it with

    const subprocess = spawn("xdg-open", [location], {
    	stdio: "inherit",
    	env: { ...process.env, XDG_CURRENT_DESKTOP: process.env.ORIGINAL_XDG_CURRENT_DESKTOP },
    })

    and it does work which makes us question whether the fix actually does anything. We tried looking at the XDGUtil but it's hard to tell if there's a bug somewhere without debugging.

  15. charlag commented on Sep 25, 2025

    @charlag

    We have made a quick test with replacing xdg-open command in path with our own custom script and sure enough, $XDG_CURRENT_DESKTOP is Unity so we are pretty sure that something about the fix does not work (anymore)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    33-x-y34-x-ybug 🪲has-repro-gistplatform/linux

    Type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions