48

Google Chrome is set as the default browser. However, it opens links in Firefox, which is undesired.

How can I make Org-mode to open links in Google Chrome?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
tobeannounced
  • 1,999
  • 1
  • 20
  • 30

8 Answers8

71

Emacs 23.2 doesn't directly support Google Chrome, but it does support a "generic" browser, and something like this should work:

(setq browse-url-browser-function 'browse-url-generic
      browse-url-generic-program "chromium-browser")

You don't mention your OS, but if it's Windows or Mac, you can try:

(setq browse-url-browser-function 'browse-url-default-windows-browser)
(setq browse-url-browser-function 'browse-url-default-macosx-browser)

And, if that doesn't work, there are other folks who have implemented 'browse-url-chrome. Google turned up the following link:

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Trey Jackson
  • 73,529
  • 11
  • 197
  • 229
  • Another suggestion, if you're a Linux Gnome user, is to have emacs defer the decision to gnome: (setq browse-url-browser-function 'browse-url-generic browse-url-generic-program "gnome-open") – Mike Dalessio Sep 11 '12 at 20:55
  • chromium-browser didn't work and neither did google-chrome, but `(setq browse-url-browser-function 'browse-url-default-macosx-browser)` worked. – incandescentman Mar 23 '13 at 17:22
  • 1
    I had to include full path, e.g.: `(setq browse-url-browser-function 'browse-url-generic browse-url-generic-program "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe")` (Windows 7) – hajovonta Jun 01 '15 at 11:50
  • 2
    Futher to @MikeDalessio's comment, if you are using any linux desktop there is a good chance that using "xdg-open" instead of "gnome-open" will run the default browser configured for your desktop, so (setq browse-url-browser-function 'browse-url-generic browse-url-generic-program "xdg-open") – NeilenMarais Jan 21 '16 at 07:50
  • Is there a way to use the $BROWSER environment variable? – CMCDragonkai Jul 26 '17 at 12:23
  • The link is broken: *"Secure Connection Failed. An error occurred during a connection to code.ohloh.net. SSL peer has no certificate for the requested DNS name. Error code: SSL_ERROR_UNRECOGNIZED_NAME_ALERT"* – Peter Mortensen Dec 15 '20 at 15:27
11

As Trey suggests, you can set it to a generic browser, but instead of "chromium-browser" use "google-chrome", like this:

(setq browse-url-browser-function 'browse-url-generic
      browse-url-generic-program "google-chrome")

That worked for me with Emacs 23.2 and Chrome 12.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Alan Turing
  • 12,223
  • 16
  • 74
  • 116
7

I have a similar problem (although the other way around: I wanted Emacs to open Firefox, but it opened Chromium).

I'm using Ubuntu 12.04 (Precise Pangolin), but already had the problem with Ubuntu 11.10 (Oneiric Ocelot). The solution below applies to Linux, maybe macOS (?), and probably not Windows.

Setting browse-url-generic-program as suggested in other answers didn't work for me. Note also that my default browser is generally Firefox: that's what most other applications are using to open a URL, including xdg-open. So I was surprised that Emacs would do otherwise.

I finally figured out that Emacs is using the sensible-browser (1) script. Looking at that script, I noticed that:

  • it first looks at the BROWSER environment variable;
  • else, it tries several other generic scripts, starting with gnome-www-browser

It so happens that, on my machine, BROWSER is not set, but gnome-www-browser is a script apparently put there by Chromium, and (naturally) running Chromium.

So, long story short: putting the following line

export BROWSER=firefox # Or any browser of your choice

in your .profile may help if Emacs is not using the correct browser.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Pierre-Antoine
  • 1,915
  • 16
  • 25
  • 1
    If you wish to eliminate chrome as default browser as a side effect of changing the emacs browser, you can do the following (I found it on bugs.launchpad.net): $ sudo update-alternatives --config gnome-www-browser [then select your preferred browser from the menu] – rytis Apr 11 '14 at 09:49
5

Setting the browser function is very easy using the GUI:

  • In the menu, click Options > Customize Emacs > Top-level customization Group
  • Click on the link External (Interfacing to external utilities.)
  • Click on the link Browse Url (Use a web browser to look at a URL.)
  • Click on the small triangle to the left of Browse Url Browser Function, this reveals a Value Menu button and some help text
  • Click the Value Menu button
  • Choose your preference from the displayed menu
  • Move to the top of the buffer, click the button Apply and Save to save the change to your ~/.emacs file

Done :-)

ack
  • 7,356
  • 2
  • 25
  • 20
1

I also had this problem when exporting org files to HTML. It would use Firefox instead of a Chromium browser. I fixed it by customizing org-file-apps (which for some reason had been set to open XHTML and HTML files with Firefox).

I now have an entry for extension \.x?html?\' with command set to the Lisp form: (browse-url file)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
enquiry
  • 106
  • 1
  • 2
1

I was on macOS and the browse-url-default-macos-browser did not work for me.

My solution was:

(setq browse-url-browser-function 'browse-url-chrome)
(setq browse-url-chrome-program "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"))
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Enze Chi
  • 1,733
  • 17
  • 28
0

For ChrUbuntu, the google-chrome incantation as given by Alan Turing works with Emacs 23.3.1, the default as of today. I suspect the chrubuntu configuration even when tickled to use chromium uses the wrong binary name.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
brucer42
  • 1
  • 1
0

In emacs 28 (Fedora Linux) I just needed this

(setq browse-url-browser-function 'browse-url-chrome)
dmvianna
  • 15,088
  • 18
  • 77
  • 106