reddit / emacs

Emacs no longer opens links in the existing instance of firefox and the new one it opens is not using my profile; have a minimally reproducible example in emacs -q, need help with either what variable I need to set or whether to report it as a bug in emacs or a bug in the snap package

MousetrapPling · 2022-04-15 11:33
Edit: the maintainer of the emacs snap asked me to raise an issue, [which I've done](https://github.com/alexmurray/emacs-snap/issues/36), and he'll look into it. **OS**: Ubuntu 20.04.4 LTS, Gnome 3.36.8 **Emacs**: GNU Emacs 28.1 (build 2, x86\_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0) of 2022-04-06; installed from the current stable snap package **Firefox**: 99.0 (edit for additional info: Firefox is installed via apt not snap, Chromium (see later) is installed via snap) **To reproduce in emacs -q**: M-x browse-url-firefox RET (url) (I’m using the wordle url to test but any url I put in place of my placeholder (url) in that command does the same). **Expected behaviour**: the url is opened in my already running instance of firefox as a new tab or if there isn’t one then it runs a new instance of firefox that uses my profile. **Actual behaviour**: the url is always opened in a new instance of firefox, this looks to the OS as if it is an Emacs window (the application bar shows me two Emacs windows not one Emacs window and one firefox window), this new instance of firefox doesn’t appear to be running my profile (I’m not logged in anywhere). Opening a second link will open it within this not-right instance of firefox. The problem started after I upgraded both emacs and firefox last week (within a few hours and I don’t think I opened any links in between). I’ve tried googling and all I can find is: [https://emacs.stackexchange.com/questions/71275/how-to-open-firefox-with-default-bookmarks-and-add-ons-profile-when-clicking-url](https://emacs.stackexchange.com/questions/71275/how-to-open-firefox-with-default-bookmarks-and-add-ons-profile-when-clicking-url) which I think is the same problem conceptualised a little differently. I don’t want to downgrade to Emacs 26.3 to fix it tho! Using the comments on this I did a little more troubleshooting. If I open a terminal outside of emacs (just a normal terminal) and do ‘xdg-open (url)’ then I get the expected behaviour. In emacs if I do ‘M-! xdg-open (url)’ then I get the buggy behaviour. Which I think means the problem is within emacs and not something just to do with firefox. (Edit: It was suggested in comments it might be my firefox profile that was the problem. So I logged into my machine as a different user to test this (so the exact same software stack but none of my customisations including not my firefox profile). I get the same buggy behaviour with browse-url-firefox as described above, so it's not my firefox profile.) I looked at the help for process-environment as suggested in the comments on stack exchange, but I’m not entirely sure what I should be looking for in the long list of variables. I can see that /usr/bin is in the path, and ‘which firefox’ tells me /usr/bin/firefox (both from the terminal and run as a shell command using M-! from within Emacs). I can see it has my home directory set properly, both as HOME and as SNAP\_REAL\_HOME, I also noticed there’s a whole bunch of things to do with snap. Poking around at browse-url to see if I could get a way to reproduce it without relying on firefox being the default browser I found there are specific commands for different browsers, and as I also have chromium installed I checked the behaviour of browse-url-chromium. I get the expected behaviour – i.e. the url is opened in the already running instance of chromium if I have one, and if a new instance is opened (because I don’t have one running) then the OS sees it as a chromium window not an emacs window and appears to be using my profile. Writing this post I also discovered that if I have opened a new not-right instance of firefox using browse-url-firefox from emacs -q then following a link from my normal emacs opens as a new tab in that not-right firefox rather than opening yet another new instance of firefox. I’m a bit stuck now. It’s clearly not a behaviour that many people are seeing, otherwise I’m sure I’d’ve found more using google (or maybe my search terms are just bad). It “feels” like some environment variable is wrong but I don’t know if I just need to set something (nor what I need to set), and if that’s not the case I’m not sure if it should be raised as a bug in emacs or a bug in the snap package. Or maybe something completely different I haven’t thought of! Can anyone help?
alexmurray · 2022-04-15 11:55
Please file a bug against the snap package with as much info as you can and I'll try look at it next week. https://github.com/alexmurray/emacs-snap (Edited to fix a typo)
MousetrapPling · 2022-04-15 12:10
I've done that now. Thank you!
lilytex · 2022-04-15 12:58
This happened to me and I simply solved deleting that profile (I think you can make a backup before wiping out your profile) I'm not sure whether this is more of a Firefox issue rather than Emacs, I don't remember updating emacs (even if it's done in the background I still need to do doom sync)
MousetrapPling · 2022-04-15 14:33
No, that doesn't seem to be the problem in this case. I think I'd already ruled out it being my firefox profile by running xdg-open (url) from inside and outside emacs and getting different behaviours. But just in case I just now logged myself in as a different user on my machine, so exactly the same software stack but none of my config including not my firefox profile. I get exactly the same buggy behaviour with browse-url-firefox as when I'm logged in as myself. Thanks for the thought tho, it was something I should've explicitly tested!
ftrx · 2022-04-15 17:29
Probably it's a snap issue: Emacs being isolated from the rest of the system can't see Firefox. I do not know how kind of holes snaps have punched to be more or less usable but honestly NOT as an Emacser (also relatively new) but as a (a bit seasoned) sysadmin: leave snap to their destiny, the dump. They have a unique and sole reason: pushing commercial model in FLOSS contributing to the annihilation of the community. They do not offer any real safety, they waste resources, encourage bad upgrades practice, cut packagers so an important source of valuable bugreports and patches while giving NOTHING to the users. Classic packages issue are fixed by NixOS/Guix system, isolation should be done when needed via cgroups (see firejail/bubblewrap). The container era is like the full-stack virtualization on x86 years ago, a business for some, a way to badly maintain bad infra instead of innovate and a failure.
demosthenex · 2022-04-15 17:49
I found recently that if dbus isn't running that you cannot open links in the running Firefox, only a new window.