73

Right now Chrome throws its apron over its head and calls Firefox, which opens the link with rtorrent. What do I need to do to eliminate the Firefox step?

Eliah Kagan
  • 116,445
  • 54
  • 318
  • 493
BevA
  • 847
  • 1
  • 7
  • 4
  • what version of Google chrome are you running? `google-chrome -version` – Alvar May 08 '12 at 08:14
  • This happened to me (on Ubuntu 14.04.2 LTS) when Firefox was set as my default browser. If Chromium was set as my default browser, then I only got a new empty tab in Chromium. -- In the end I solved the problem by patching my `/usr/bin/xdg-open` as suggested in the accepted answer to "[Torrent magnet links open new window but not transmission](http://askubuntu.com/questions/311537/torrent-magnet-links-open-new-window-but-not-transmission)". – zrajm May 31 '15 at 13:54

11 Answers11

92

Chrome (or Chromium) protocol handling works differently than in Firefox. Firefox basically keeps track of all that itself, which is why you can configure protocol handling (like magnet links) in the Applications part of the Preferences. Chrome, however, relies on xdg-open.

There are a couple things that you need to do before xdg-open will handle magnet links properly.

  1. Find the name of the desktop file of the program you want to handle the magnet link. Let's suppose the program is Transmission. It (like usual) has its desktop file in /usr/share/applications/ and in fact, by perusing the listing of the directory, I find that my version of transmission is actually the gtk version, so its desktop file is called transmission-gtk.desktop.

  2. It's possible the desktop file is messed up. So you can check that /usr/share/applications/transmission-gtk.desktop contains the lines:

    Exec=transmission-gtk %U
    [some lines omitted]
    MimeType=application/x-bittorrent;x-scheme-handler/magnet;
    

    Note the %U in the Exec line. It's absolutely necessary. The MimeType line should look as above.

  3. Now for the essential step to tell xdg-open to open magnet links using Transmission. In the terminal, type:

    xdg-mime default transmission-gtk.desktop x-scheme-handler/magnet 
    
  4. (Step not necessary if you use Gnome, KDE, Xfce, or LXDE) Lastly, xdg-open assumes you are running one of the standard desktop environments: gnome, kde, xfce and lxde. If you are not, xdg-open will not work on magnet links. As suggested on the Arch wiki, you can simply modify /usr/bin/xdg-open. At the end of the file, you'll find a portion that starts with:

    detectDE
    if [ x"$DE" = x"" ]; then
       DE=generic
    

    change generic to one of gnome, kde, xfce, or lxde. I chose xfce since I actually have an Xfce session that I've configured and use on occasion.

    The downside to this approach is that if xdg-open gets updates, you'll have to redo this. The Arch wiki suggests another approach that avoids this flaw (but has its own downside).

    Warning: The choice in the last step is more important than it might seem. Picking lxde did not work for me! In xdg-open, the helper function open_lxde relies on pcmanfm (lxde file manager) and something is wrong with either the code in open_lxde or perhaps it's pcmanfm's fault.

Chan-Ho Suh
  • 7,544
  • 4
  • 41
  • 73
  • 7
    Thank you! I just did a `xdg-mime default deluge.desktop x-scheme-handler/magnet` to associate it with Deluge instead. – Justin Force Jan 01 '13 at 05:34
  • Worked for me. On Fedora 18 with KDE it started working after step 2. Step 3 and 4 were not necessary. – Maxim Egorushkin Jan 22 '13 at 19:55
  • 1
    I'm having a (probably) [related problem](http://askubuntu.com/questions/311537/torrent-magnet-links-open-new-window-but-not-transmission). I've tried your solution but it's not working. – Quinn Culver Jul 13 '13 at 15:46
  • 2
    How can Linux succeed, when experts let alone noobs can't make it work. I use Linux by preference every day, but the desktop experience is not good enough. Good luck to SteamOS. – Sam Watkins Nov 29 '13 at 11:05
  • Linux is not "so messed up these days". Linux has and always will be fragmented, which is good because it gives us choice and fosters competition to create the best software. It can on occasion be difficult IF you're doing something outside of what your particular distribution's authors planned on. That's the trade-of for an otherwise awesome and free OS (in both the "freedom" and "free beer" sense). And luckily in those rare instances we now have great sites like askubuntu.com to make solving problems less painful (certainly a lot less painful solving than Linux problems used to be). – machineghost Jan 18 '14 at 20:14
  • 2
    Also wanted to say thanks for the answer, it worked great. Since I'm on Linux Mint using MATE instead of GNOME, I had to do step 4. Strangely, `mate` didn't work (which I would have expected since I run MATE), but `gnome` did. – machineghost Jan 18 '14 at 20:16
  • 1
    @machineghost thanks for your comment: i'm on MATE too and this answer + your comment sorted it for me. – Max Williams Apr 07 '14 at 10:04
  • I'm using Awesome window manager, and xdg-open worked with magnet links without the hack you suggested. I'm using xdg-utils 1.1.0. Does this mean that this issue is solved? – Hubro Sep 26 '14 at 10:39
  • Thank you! Step 3 was the part I was missing... couldn't find that info anywhere else. – cowsay Nov 18 '15 at 05:43
  • changing generic to xfce worked like super! Thanks – Ali Almoullim Dec 27 '16 at 22:29
  • Didn't work for me. I tried using it to forward all magnet: links to my custom handler. xdg-open uses my custom handler, but not chrome! wth, chrome! – enigmaticPhysicist Oct 03 '17 at 09:21
  • On my KDE (Kubuntu) I had to also run `update-mime-database -V ~/.local/share/mime` before the `xdg-mime default ...` change would take effect. I haven't seen this in all the answers so maybe it's the reason it didn't work for some people. – Elias Kouskoumvekakis Apr 28 '19 at 23:50
8

just drag the magnet link into Transmission window and it works fine for me without any tweaks.... I am using a stock build of Lubuntu 12.10 nothing fancy....

khorosho
  • 81
  • 1
  • 2
  • This is another approach and I like it. But it doesn't solve the issue when the magnet link is opened automatically and it requires much user interaction (clicks) when transmission isn't already running. – Joel Sjögren Jul 22 '13 at 08:11
2

In Ubuntu 20.04, run one of the following commands.

Webtorrent

xdg-mime default webtorrent-desktop.desktop x-scheme-handler/magnet

Transmission

xdg-mime default transmission-gtk.desktop x-scheme-handler/magnet

Any other torrent application

X.desktop file must exist in the /usr/share/applications directory

Ben Winding
  • 713
  • 9
  • 13
2

Worked very nice to open magnets from Chrome with qBitorrent in Lubuntu

xdg-mime default qBittorrent.desktop x-scheme-handler/magnet

Mariuz
  • 235
  • 2
  • 7
1

if you use xfce and don't want to mess anything, you could use my solution. I fixed by manually editing xdg-open as follows:

First of all make sure you have the mime associated (as explained before, with xdg-mime)

Then backup xdg-open as root (sudo if that applies)

# cp /usr/bin/xdg-open /usr/bin/xdg-open.old

Finally, edit as root /usr/bin/xdg-open, find open_xfce() and add the lines marked with +, e.g., with nano

# nano /usr/bin/xdg-open

open_xfce()
+ if [ "\`echo $1 | sed -n 's/\(^[[:alnum:]+\.-]*\):.*$/\1/p'\`" == "magnet" ]; then
+     gnome-open "$1"
+ else
      exo-open "$1"
+ fi

it only adds the exception for the magnet links, so they will be opened with gnome-open instead of exo-open.

Hope it helps.

1

None of the other suggestions I found worked for me, but this did the trick under Debian / Xfce ( from http://fluxcode.net/archives/57 ):

In /usr/bin/xdg-open add the following lines to open_xfce()

open_xfce()
{
 if(echo "$1" | grep -q '^magnet:'); then
    transmission-gtk "$1" 
    if [ $? -eq 0 ]; then
       exit_success
    fi
 fi

exo-open "$1"
Braiam
  • 66,947
  • 30
  • 177
  • 264
Tom
  • 11
  • 1
0

This works for me in ubuntu 18 with FF (for deluge):

gio mime x-scheme-handler/magnet deluge.desktop

I know that doesn't answer the question but I use Chrome too and this is a better work around than copying and pasting the magnet link.

uvasal
  • 493
  • 1
  • 8
  • 21
0

A guy in alt.os.linux.slackware found the solution:

http://www.void.gr/kargig/blog/2012/01/24/open-magnet-urls-with-xdg-open/

BevA
  • 847
  • 1
  • 7
  • 4
  • Welcome to Ask Ubuntu! While this may theoretically answer the question, [it would be preferable](http://meta.stackexchange.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Michael Martin-Smucker Mar 02 '12 at 03:10
  • This is actually more complicated than needed. See my answer. – Chan-Ho Suh May 08 '12 at 08:09
0

Using gnome-open on XFCE worked out for me.

This can be forced with editing /usr/bin/xdg-open and change

if [ x"$DE" = x"" ]; then
  DE=generic
fi

to

if [ x"$DE" = x"" ]; then
  DE=generic
fi
DE=gnome
brillout
  • 1,399
  • 3
  • 14
  • 21
0

I've tried for years to fix this and switch to Chrome and nothing seems to work. I finally had a thought I'm not sure why I didn't think of before and it works great. I'm using Tixati in Mint but it should work universally. Chrome points magnet links to usr/bin/transmission-gtk so I renamed that to transmission-gtk.old and renamed tixati to transmission-gtk and picked the option in chrome to always do this and hit launch app and now mag links go straight into Tixati just like Firefox. Problem finally solved!

-1

I mixed few answers (that unfortunately didn't work for me) and came up with something that made it work like a charm! It worked on Linux Mint 16 under XFCE, anyways.

Make backup of xdg-open under /usr/bin, open your xdg-open with sudo and then make open_xfce() function exactly like this:

open_xfce()
{    
    if (echo "$1" | grep -q '^magnet:'); then
        gnome-open "$1"
    else
        exo-open "$1"
    fi
}

It's dirty and you need to edit it every xdg-open update, but hey, it works!