Org-roam-protocol not appending body

I am using org-roam-protocol with mac Catalina along with roam-ref protocol . I have a bookmarklet with the following code

javascript:location.href =
    + encodeURIComponent(location.href)
    + '&title='
    + encodeURIComponent(document.title)
    + '&body='
    + encodeURIComponent(window.getSelection())

When i click the bookmark everything works as expected other than body part . The selected text is not being displayed . If i change the code to

javascript:location.href =
    + encodeURIComponent(location.href)
    + '&title='
    + encodeURIComponent(window.getSelection())

The title becomes the selected text . ie; window.getSelection is working but body part is not working . Do anybody have any idea on what is going on and what have i done wrong ?

I suggest you edebug the function org-roam-protocol-open-ref – I don’t use org-roam-protocol but it appears the body is expected in the code. You should be able to track down what’s happening with the text in the body parameter coming from the browser.

I’ve found the same issue while trying to set this up, following the steps in the manual.

I’m still learning elisp so my debugging skills are limited, but this is what I’ve found so far:

Set debug-on-entry:

(debug-on-entry 'org-roam-protocol-open-ref) 

Then run this from a shell:

  /usr/local/bin/emacsclient --no-wait \

org-roam-protocol-open-ref((:ref “debug-protocol-body” :title “test-protocol-body-title” :body “foobody”))

This doesn’t really help much yet, but it at least shows that the body param is making it into the function.

Total stab in the dark: maybe my capture template is missing something that gives the body a place to go? Currently I’m using an unmodified default template.

Ok, it took some head scratching and learning but I’ve figured out what this issues is, and it’s not a bug but a combination of things which are probably not obvious to someone new to org mode (and emacs in general).

My suspicion that the root issue with body not showing up in the capture was becasue the template didn’t specificy a place to put “body” seems correct. There’s no default assumption or logic to put a parameter named “body” in capture.

It would have been easy going to prove this, but I also got seriously confused by the difference between org-roam-capture-templates and org-roam-capture-ref-templates. org-roam-protocol requires making changes to the ref templates in order to specify a place for body. Here’s a simple example:

  (setq org-roam-capture-ref-templates
        '(("r" "ref" plain
          (file+head "${slug}.org" "#+title: ${title}\n${body}")
          :unnarrowed t)))

While initially this was unintuitive, I’m really excited about how flexible this is. In combination with the templating engine this provides the basis of some powerful capture!