From 84de1aec4532d36d24002ad2dcbc67993ff5c3c4 Mon Sep 17 00:00:00 2001 From: Max Nikulin Date: Mon, 16 Dec 2024 21:46:49 +0700 Subject: [PATCH] org-protocol: Add void() to bookmarklets * doc/org-manual.org (The store-link protocol): (The capture protocol, The open-source protocol): * lisp/org-protocol.el (org-protocol-store-link): (org-protocol-capture, org-protocol-open-source): Update javascript: bookmarklets to discard assigned value. Firefox-133 may treat expression value as document content to render. Reported by: Rehan Deen. [BUG] Org-protocol bookmarklets in Firefox behaving badly after recent upgrade. Thu, 12 Dec 2024 13:42:34 +0530. Link: --- doc/org-manual.org | 20 ++++++++++---------- lisp/org-protocol.el | 34 +++++++++++++++++----------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index 0f6d6a067..10900f738 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -21318,15 +21318,15 @@ *** The ~store-link~ protocol name, e.g., =Org: store-link= and enter this as /Location/: #+begin_example -javascript:location.href='org-protocol://store-link?' + - new URLSearchParams({url:location.href, title:document.title}); +javascript:void(location.href='org-protocol://store-link?' + + new URLSearchParams({url:location.href, title:document.title})); #+end_example Title is an optional parameter. Another expression was recommended earlier: #+begin_example -javascript:location.href='org-protocol://store-link?url='+ - encodeURIComponent(location.href); +javascript:void(location.href='org-protocol://store-link?url='+ + encodeURIComponent(location.href)); #+end_example The latter form is compatible with older Org versions from 9.0 to 9.4. @@ -21347,19 +21347,19 @@ *** The ~capture~ protocol =Org: capture=, and enter this as =Location=: #+begin_example -javascript:location.href='org-protocol://capture?' + +javascript:void(location.href='org-protocol://capture?' + new URLSearchParams({ template: 'x', url: window.location.href, - title: document.title, body: window.getSelection()}); + title: document.title, body: window.getSelection()})); #+end_example You might have seen another expression: #+begin_example -javascript:location.href='org-protocol://capture?template=x'+ +javascript:void(location.href='org-protocol://capture?template=x'+ '&url='+encodeURIComponent(window.location.href)+ '&title='+encodeURIComponent(document.title)+ - '&body='+encodeURIComponent(window.getSelection()); + '&body='+encodeURIComponent(window.getSelection())); #+end_example It is a bit more cluttered than the former one, but it is compatible @@ -21391,8 +21391,8 @@ *** The ~open-source~ protocol a bookmark with the following location: #+begin_example -javascript:location.href='org-protocol://open-source?&url='+ - encodeURIComponent(location.href) +javascript:void(location.href='org-protocol://open-source?&url='+ + encodeURIComponent(location.href)) #+end_example #+vindex: org-protocol-project-alist diff --git a/lisp/org-protocol.el b/lisp/org-protocol.el index 85c9a0cc5..c9ef10f31 100644 --- a/lisp/org-protocol.el +++ b/lisp/org-protocol.el @@ -97,19 +97,19 @@ ;;; Commentary: ;; You may use the same bookmark URL for all those standard handlers and just ;; adjust the sub-protocol used: ;; -;; javascript:location.href='org-protocol://sub-protocol?'+ +;; javascript:void(location.href='org-protocol://sub-protocol?'+ ;; new URLSearchParams({ ;; url: location.href, ;; title: document.title, -;; body: window.getSelection()}) +;; body: window.getSelection()})) ;; ;; Alternatively use the following expression that encodes space as \"%20\" ;; instead of \"+\", so it is compatible with Org versions from 9.0 to 9.4: ;; -;; location.href='org-protocol://sub-protocol?url='+ +;; javascript:void(location.href='org-protocol://sub-protocol?url='+ ;; encodeURIComponent(location.href)+'&title='+ ;; encodeURIComponent(document.title)+'&body='+ -;; encodeURIComponent(window.getSelection()) +;; encodeURIComponent(window.getSelection())) ;; ;; The handler for the sub-protocol \"capture\" detects an optional template ;; char that, if present, triggers the use of a special template. @@ -436,15 +436,15 @@ (defun org-protocol-store-link (fname) The location for a browser's bookmark may look like this: - javascript:location.href = \\='org-protocol://store-link?\\=' + - new URLSearchParams({url:location.href, title:document.title}); + javascript:void(location.href = \\='org-protocol://store-link?\\=' + + new URLSearchParams({url:location.href, title:document.title})); or to keep compatibility with Org versions from 9.0 to 9.4 it may be: - javascript:location.href = \\ + javascript:void(location.href = \\ \\='org-protocol://store-link?url=\\=' + \\ encodeURIComponent(location.href) + \\='&title=\\=' + \\ - encodeURIComponent(document.title); + encodeURIComponent(document.title)); Don't use `escape()'! Use `encodeURIComponent()' instead. The title of the page could contain slashes and the location @@ -478,24 +478,24 @@ (defun org-protocol-capture (info) This function detects an URL, title and optional text, separated by `/'. The location for a browser's bookmark looks like this: - javascript:location.href = \\='org-protocol://capture?\\=' + + javascript:void(location.href = \\='org-protocol://capture?\\=' + new URLSearchParams({ url: location.href, title: document.title, - body: window.getSelection()}) + body: window.getSelection()})) or to keep compatibility with Org versions from 9.0 to 9.4: - javascript:location.href = \\='org-protocol://capture?url=\\='+ \\ + javascript:void(location.href = \\='org-protocol://capture?url=\\='+ \\ encodeURIComponent(location.href) + \\='&title=\\=' + \\ encodeURIComponent(document.title) + \\='&body=\\=' + \\ - encodeURIComponent(window.getSelection()) + encodeURIComponent(window.getSelection())) By default, it uses the character `org-protocol-default-template-key', which should be associated with a template in `org-capture-templates'. You may specify the template with a template= query parameter, like this: - javascript:location.href = \\='org-protocol://capture?template=b\\='+ ... + javascript:void(location.href = \\='org-protocol://capture?template=b\\='+ ...) Now template ?b will be used." (let* ((parts @@ -555,14 +555,14 @@ (defun org-protocol-open-source (fname) The location for a browser's bookmark should look like this: - javascript:location.href = \\='org-protocol://open-source?\\=' + - new URLSearchParams({url: location.href}) + javascript:void(location.href = \\='org-protocol://open-source?\\=' + + new URLSearchParams({url: location.href})) or if you prefer to keep compatibility with older Org versions (9.0 to 9.4), consider the following expression: - javascript:location.href = \\='org-protocol://open-source?url=\\=' + \\ - encodeURIComponent(location.href)" + javascript:void(location.href = \\='org-protocol://open-source?url=\\=' + \\ + encodeURIComponent(location.href)") ;; As we enter this function for a match on our protocol, the return value ;; defaults to nil. (let (;; (result nil) -- 2.39.5