#1071578 browse-url silently fails on some wayland corner cases

Package:
emacs-pgtk
Source:
emacs-pgtk
Description:
GNU Emacs editor (with GTK+ Wayland GUI support)
Submitter:
Antoine Beaupre
Date:
2025-03-18 15:33:01 UTC
Severity:
normal
#1071578#5
Date:
2024-05-21 13:34:33 UTC
From:
To:
After upgrading from Emacs 28 to 29 and switching from xorg to
wayland, I have noticed emacs sometimes fail to open URLs. It seems to
be an ordering issue in my session: it seems like Emacs sometimes
starts before Sway is fully setup and the environment properly
populated, which makes it use the incorrect WAYLAND_DISPLAY variable.

This, in itself, is a bug in my setup: Emacs should be started
properly.

*But* my bug here is this fails completely silently. No URL gets
opened at all, which is *really* disruptive because I can open a bunch
of URLs while reading my mail, then i go to my browser and nothing is
there and now I've lost data.

Instead, browse-url should fail noisily if it fails to load a URL. If
I look at the `browse-url' source, for example at the end we see this
kind of failure, which happens when no browser can be found at all:

    (if (functionp function)
        (apply function url args)
      (error "No suitable browser for URL %s" url))))

That is what I would expect the handler to do in this case, something
like "uh, we can't find your wayland display, so we're just dropping
this URL to the floor, sorry".

That function also has that mysterious blob:

              (progn
                ;; The `display' frame parameter is probably wrong.
                ;; See bug#53969 for some context.
                ;; (setenv "WAYLAND_DISPLAY" dpy)
                )
            (setenv "DISPLAY" dpy)))

... which refers to:

https://debbugs.gnu.org/cgi/bugreport.cgi?bug=53969

... which I'm struggling to understand. If I uncomment that blob, the
bug, actually, just completely goes away which i find quite puzzling.

A.

#1071578#10
Date:
2025-03-18 15:31:33 UTC
From:
To:
[...]

Unsure if it is related to Wayland or pgtk and it is almost certainly an
upstream issue rather then a Debian-specific bug.

The `browse-url' package spawns external processes using shoot and
forget approach that does not allow error handling.

There is another method to invoke external applications that is used in
`mailcap-view-file' and `org-open-file', but it has disadvantages as
well. It is not possible to detach external handler process from emacs,
so in some cases it is not possible to quit from Emacs keeping launched
applications running. Developers believed there is another problem, but
did not bother to explain it (discussions were long and rather
disappointing).

You may try to report the issue to the Emacs developers. However related
`browse-url' code has long history of changes and I am in doubts it can
be improved without improvements of the library used to spawn external
processes.