3 minute read

TL;DR: Don’t use snap if you want to use Org Capture (or xdg-open with any custom schemes).

I use org mode for my brain management, it collects and tracks all my TODOs, organizes my workflows and acts as a scratch pad for my code snippets and much more. To capture text and links from browsers, there’s org-protocol in Emacs which allows external tools to invoke org mode, This is in turn used by Org Capture extension to transfer the data into org.

After upgrading Ubuntu to 22.04 Org Capture is once again broken on Firefox. Let’s try to figure out why.

Test 1: Verify org-protocol works

emacsclient -n "org-protocol:///capture?url=http%3a%2f%2fduckduckgo%2ecom&title=DuckDuckGo"

Success! Emacs opens the template windows. I knew this would work, since Org Capture still works on Chrome.

Test 2: Enable debug logging on the add-on

Manage Extension->Preferences->Debug. Save.

> Capturing the following URI with new org-protocol:  org-protocol://capture?template=L&url=https%3A%2F%2Fduckduckgo.com%2F&title=DuckDuckGo%20%E2%80%94%20Privacy%2C%20simplified.&body=

So the add-on works.

Test 4: MIME is registered

$ xdg-mime query default x-scheme-handler/org-protocol
$ xdg-open "org-protocol://capture?template=L&url=https%3A%2F%2Fduckduckgo.com%2F&title=DuckDuckGo%20%E2%80%94%20Privacy%2C%20simplified.&body="

Success! So that works. Again, this is expected as it works on Chrome.

Test 5: Protocol handler invocation from FF

Now that I have the developer console open I can browse into the code and set a breakpoint to capture.js:56, the location where it tries to send Firefox to the org protocol URI with location.href = uri.

The uri is "org-protocol://capture?template=L&url=https%3A%2F%2Fduckduckgo.com%2F&title=DuckDuckGo%20%E2%80%94%20Privacy%2C%20simplified.&body=".

I can invoke location.href = uri and sure enough, nothing happens. So now I know it doesn’t understand the org-protocol protocol, or does nothing with it.

The instructions on setting this up seem a bit vague, so let’s try to understand the entire thing. So off to Register Protocol Documentation. The instructions say (for non gconf users):

Firefox 3.5 and above

(Works without installed Gnome libraries)

  • Type about:config into the Location Bar (address bar) and press Enter.
  • Right-click -> New -> Boolean -> Name: network.protocol-handler.expose.foo -> Value -> false (Replace foo with the protocol you’re specifying)
  • Next time you click a link of protocol-type foo you will be asked which application to open it with.

Not encouraging that the instructions talk about version 3.5 and the page was last modified on 2011. My version is 101.0.1. But let’s continue anyway, it did work very recently anyway. Since I have done this already and I’m in regression mode, It’s double checking mode.

  • network.protocol-handler.expose.org-protocol is false

Dead end. I tried the gconf commands as well with no avail.

Test 6: Reinstall extension

No effect.

Test 7: Revalidate org-capture documentation

Re-reading org-protocol documentation gave no new insight.

Let’s create a web page to test:

  <a href="org-protocol://capture?template=L&url=https%3A%2F%2Fduckduckgo.com%2F&title=DuckDuckGo%20%E2%80%94%20Privacy%2C%20simplified.&body=">Org link</a>

Works on Chrome. Not that this is any different from invoking location.href.

Test 8: Make sure there are no application associations to org-protocol in Firefox settings

There was, clearing it I was able to see the “launch external app” dialog to appear, but after that nothing.

So now I know that FF does understand the protocol, but for some reason it fails to invoke the xdg-open or whatever mechanism it uses to launch the external tool.

What has changed in 22.04?

Hmm.. snap has changed. Could it be? No.. Could it? Googling.. Sure enough, it has issues. So next test install Firefox with deb.

Works like charm.

F you snap.

So what is actually required?

I don’t want to start this all over but my guess is:

  • Install org-protocol.
  • Especially make sure Desktop Entry with the protocol association.
  • Install Org Capture extension.
  • Don’t use snap.
  • Profit.

Can it be made to work with snap? By that snap thread it should work(?) but doesn’t. I don’t know or care. There’s a bug to track. I’m out.

Tagged under: emacs org-mode firefox