You are not logged in.

#1 2012-12-03 02:59:52

ackalker
Member
Registered: 2012-11-27
Posts: 201

Overriding Chromium's internal protocol handlers (mailto:, news:, etc)

After reading many posts on different forums, I have found that overriding Chromium's internal protocol handlers is notoriously difficult. Some, like mailto:, use a hardcoded command name like xdg-email which doesn't work very well when not using one of the major desktops, while others don't work as expected for any number of reasons.

Which is why I've come up with a way to add any user-defined protocol that Chromium doesn't already handle using xdg-open.

The following example deals with adding an override for the mailto: protocol handler, to have it use xdg-open instead of xdg-email to start the email client.

The process is in 3 steps:

1. Add a .desktop file for the protocol handler override
2. Tell the system to use the protocol handler override
3. Tell Chromium to use the protocol handler override

Step 1: Create the file $HOME/.local/share/applications/chromium-mailto.desktop with the following contents:

[Desktop Entry]
Version=1.0
Name=Chromium mailto: override
Comment=Override the Chromium mailto: protocol handler
GenericName=Override the Chromium mailto: protocol handler
Exec=xdg-open $(echo %u|perl -pe 's/^x-chromium-mailto://; tr/+/ /; s/%([a-fA-F0-9]{2,2})/chr(hex($1))/eg;')
Terminal=false
Type=Application
MimeType=x-scheme-handler/x-chromium-mailto
NoDisplay=true

Step 2: Tell the system about the new MIME type

In a terminal, execute the following command:

$ xdg-mime default chromium-mailto.desktop x-scheme-handler/x-chromium-mailto

Note: the path to the .desktop file must be relative to $HOME/.local/share/applications !

Step 3: Tell Chromium to use the protocol handler override

First, close all open Chromium windows. This is very important for the following changes to 'take'!
Assuming you use the Default profile in Chromium, open the following file in an editor: $HOME/.config/chromium/Default/Preferences
Within the curly braces, for example under the lines:

   "cloud_print": {
      "email": ""
   },

add the following:

   "custom_handlers": {
      "enabled": true,
      "registered_protocol_handlers": [ {
         "default": true,
         "protocol": "mailto",
         "title": "mailto: override",
         "url": "x-chromium-mailto:%s"
      } ]
   },

Test that everything works by starting Chromium, then clicking on a mailto: link, for example the Contact link at the bottom of http://oswatershed.org.
The first time you click the link, Chromium will ask for permission to run the command, so you can check that it is correct. Check the checkbox to have Chromium remember your choice.

Comments and suggestions are very welcome.

Last edited by ackalker (2012-12-04 04:08:32)

Offline

#2 2012-12-03 03:12:55

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: Overriding Chromium's internal protocol handlers (mailto:, news:, etc)

Nice. Moving to Community Contributions.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2012-12-03 03:59:34

ackalker
Member
Registered: 2012-11-27
Posts: 201

Re: Overriding Chromium's internal protocol handlers (mailto:, news:, etc)

Thanks :-)

Offline

#4 2014-04-23 20:12:03

rbrband
Member
Registered: 2014-04-23
Posts: 2

Re: Overriding Chromium's internal protocol handlers (mailto:, news:, etc)

The Preferences file has changed since Dec. 2012. The "cloud_print" input has changed. Adding your mod input to the Preferences file induced a Google warning--I undid. It seems that the previous mods prove sufficient. Thanks!

Last edited by rbrband (2014-04-23 20:13:40)

Offline

#5 2015-01-30 13:44:07

obb
Member
Registered: 2013-12-22
Posts: 2

Re: Overriding Chromium's internal protocol handlers (mailto:, news:, etc)

Thank you. Works with Chromium Version 39.0.2171.99 (64-bit).

Last edited by obb (2015-01-30 13:45:23)

Offline

Board footer

Powered by FluxBB