jlebon / textern

A Firefox add-on for editing text in your favourite external editor!
GNU General Public License v3.0
138 stars 21 forks source link

compatible with "snap" firefox? #81

Open jhnc opened 1 year ago

jhnc commented 1 year ago

When updating from Ubuntu 20.04 to 22.04, firefox changes from traditional package to a "snap" package.

textern's make native-install USER=1 option assumes that installation should be to ~/.local and ~/.mozilla/.... However, with "snap", the paths are different (and I guess much more).

I see many reports of other software breaking that needs to interact with "snap" or "flatpak" programs.

Is it expected that textern works with "snap" firefox? If so, what is the installation procedure?

jlebon commented 1 year ago

I don't have a system to test this, but if you or someone finds out the right path to use, I'd be happy to accept a patch with possible tweaks to the Makefile and appropriate docs.

FelixJacobi commented 1 year ago

Not, it is not, as Native Messaging does not work due the Snap sandbox (Firefox is not allowed to start any executable outside of its sandbox), so it cannot access the editor executable on your system. It would work, if you would install the editor and Textern into the Snap image, which is not possible in practice.

There is an issue in Bugzilla tracking the missing support: 1661935 - Snap does not support NativeMessaging

FelixJacobi commented 1 year ago

Update: With the recent update of the Firefox snap, it should work now 🎉 .

To make it work:

mkdir -p ~/snap/firefox/common/.mozilla/native-messaging-hosts
mkdir -p ~/snap/firefox/common/.mozilla/firefox
mkdir -p ~/.mozilla
cd ~/.mozilla
ln -s ../snap/firefox/common/.mozilla/firefox
ln -s ../snap/firefox/common/.mozilla/native-messaging-hosts

Run make native-install USER=1 again, restart Firefox and the next time when you press the keyboard shortcut to launch the editor, you should get a permission prompt from your desktop environment to allow Firefox to run the external executable for native messaging.

jhnc commented 1 year ago

Thanks! I got it to work with 107.0-2/2088 using @FelixJacobi 's instructions. I had to manually create ~/snap/firefox/common/.mozilla/native-messaging-hosts/.

I use xfce4-terminal which seems to need the --disable-server option.

Is it expected that empty directories accumulate in /run/user/$(id -u)/textern/ ?

FelixJacobi commented 1 year ago

I had to manually create ~/snap/firefox/common/.mozilla/native-messaging-hosts/.

Thanks, missed that. I've updated my comment to include these.

jlebon commented 1 year ago

Instead of creating the symlinks, does it work if you do

$ make native-install USER=1 MOZILLA_NATIVE=$HOME/.mozilla/native-messaging-hosts

?

FelixJacobi commented 1 year ago

Instead of creating the symlinks, does it work if you do

$ make native-install USER=1 MOZILLA_NATIVE=$HOME/.mozilla/native-messaging-hosts

?

Yeah, could work also. I created the symlink, as there are some other applications utilizing native messaging and assuming that native-messaging-hosts is located in ~/.mozilla.

jlebon commented 1 year ago

Ack makes sense. Would appreciate a patch to add instructions for Firefox snaps if anyone is interested (maybe at the same level as https://github.com/jlebon/textern#firejail). Extra points to also cover snaps of editors if it requires any special knowledge (maybe at the same level as https://github.com/jlebon/textern#flatpak). :)

chubin commented 1 year ago

I have the same problem, probably (or maybe something else, I am not sure). But I am using Ubuntu with firefox running from /snap/.

What I did:

  1. Installed the extension.
  2. Installed textern using

    make native-install USER=1 MOZILLA_NATIVE=$HOME/.mozilla/native-messaging-hosts

Installed and configured my editor (gvim).

After that, I tried to call it with ctrl-shift-d, but nothing happened. After pressing the key combination again, I received the message "this buffer is being edited" (or similar).

I tried to set touch /tmp/111 instead of gvim, but without success. The same message (and by the way, I don't know how to cancel this "editing" state). The file (/tmp/111) was not created.

I also checked the process textern, and I didn't find it among the running processes.

dmusican commented 1 week ago

Like @chubin, I've followed the above instructions, and I'm unable to get textern to work with snap Firefox. Here is the error I see in the console:

NS_ERROR_ILLEGAL_VALUE: Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsINativeMessagingPortal.closeSession]