From 660fcd9a877cfa10f92f38dcda2bdb5852b14357 Mon Sep 17 00:00:00 2001 From: Paul Nelson Date: Thu, 22 Jan 2026 06:52:45 +0100 Subject: [PATCH 1/3] Fix Firefox profiles.ini parsing * overleaf.el (overleaf-read-cookies-from-firefox): Avoid calling match-string when string-match fails while parsing profiles.ini blocks. Fixes #28. --- overleaf.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/overleaf.el b/overleaf.el index 525ff2a..c5e8082 100644 --- a/overleaf.el +++ b/overleaf.el @@ -118,10 +118,10 @@ profile. Otherwise prompt." (mapcar (lambda (block) (save-match-data (when-let* - ((path (progn (string-match "^Path=\\(.*?\\)$" block) - (match-string 1 block))) - (name (progn (string-match "^Name=\\(.*?\\)$" block) - (match-string 1 block)))) + ((path (and (string-match "^Path=\\(.*?\\)$" block) + (match-string 1 block))) + (name (and (string-match "^Name=\\(.*?\\)$" block) + (match-string 1 block)))) `(:fields (,name) :data ,path)))) profile-blocks))) From 03939fad5307ef62ea982e35bdda5c14f6f5352d Mon Sep 17 00:00:00 2001 From: Paul Nelson Date: Thu, 22 Jan 2026 14:30:40 +0100 Subject: [PATCH 2/3] Refactor Firefox cookie retrieval into helper * overleaf.el (overleaf--sqlite-select-firefox-overleaf-cookies): New helper function. (overleaf-read-cookies-from-firefox): Use it. --- overleaf.el | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/overleaf.el b/overleaf.el index c5e8082..03c13fb 100644 --- a/overleaf.el +++ b/overleaf.el @@ -93,6 +93,24 @@ To be used with `overleaf-cookies'." (insert-file-contents (expand-file-name file)) (read (string-trim (buffer-string)))))) +(defun overleaf--sqlite-select-firefox-overleaf-cookies (dbfile) + "Return Overleaf cookies from Firefox cookie DBFILE. +Returns a list of (host cookie-string expiry)." + (let ((db (sqlite-open dbfile))) + (unwind-protect + (mapcar + (lambda (row) + (pcase-let* ((`(,domain ,name ,value ,expiry) row)) + `(,domain + ,(format "%s=%s" name value) + ,expiry))) + (sqlite-select + db + (concat + "SELECT host, name, value, expiry FROM moz_cookies " + "WHERE name = 'overleaf_session2' OR name = 'overleaf.sid'"))) + (sqlite-close db)))) + ;;;###autoload (cl-defun overleaf-read-cookies-from-firefox (&key (firefox-folder "~/.mozilla/firefox/") (profile nil)) "Make a cookie saving function reading the database at FIREFOX-FOLDER. @@ -137,20 +155,8 @@ profile. Otherwise prompt." (cookie-file (if profile (expand-file-name (concat firefox-folder "/" profile "/cookies.sqlite")) - (user-error "Profile does not exist"))) - (db (sqlite-open cookie-file)) - (result - (mapcar - (lambda (row) - (pcase-let* ((`(,domain ,name ,value ,expiry) row)) - `(,domain - ,(format "%s=%s" name value) - ,expiry))) - (sqlite-select - db "SELECT host, name, value, expiry FROM moz_cookies WHERE name = 'overleaf_session2' OR name = 'overleaf.sid'")))) - - (sqlite-close db) - result) + (user-error "Profile does not exist")))) + (overleaf--sqlite-select-firefox-overleaf-cookies cookie-file)) (user-error "Sqlite not available!")))) (defvar overleaf-save-cookies (lambda (cookies) From 1b24c23d710dec95c4854b37c6deabada4ca163b Mon Sep 17 00:00:00 2001 From: Paul Nelson Date: Thu, 22 Jan 2026 14:35:22 +0100 Subject: [PATCH 3/3] Read Firefox cookies via temporary database copy * overleaf.el (overleaf-read-cookies-from-firefox): Try to read cookies.sqlite in place; on sqlite errors, try copying the database to a temporary directory and querying the copy. * README.org (Firefox): Update docs. Fixes #29. --- README.org | 8 ++++++-- overleaf.el | 24 +++++++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/README.org b/README.org index ccced8a..101448e 100644 --- a/README.org +++ b/README.org @@ -67,10 +67,14 @@ file: *** Firefox Locate you Firefox profile folder and set: #+begin_src emacs-lisp - (setq overleaf-cookies - (overleaf-read-cookies-from-firefox [optional: :profile ""] )) +(setq overleaf-cookies + (overleaf-read-cookies-from-firefox + [optional: :firefox-folder ""] + [optional: :profile ""])) #+end_src This assumes that you're logged into overleaf in this Firefox profile. +On GNU/Linux, the default == is typically =~/.mozilla/firefox/=. +On macOS, == is typically =~/Library/Application Support/Firefox=. *It is recommended that no Firefox instance using this profile is running while =overleaf.el= is accessing the cookie database. The cookies usually tend to be evicted from the database while Firefox is running and will only be put back upon closure.* diff --git a/overleaf.el b/overleaf.el index 03c13fb..9e05feb 100644 --- a/overleaf.el +++ b/overleaf.el @@ -156,7 +156,29 @@ profile. Otherwise prompt." (if profile (expand-file-name (concat firefox-folder "/" profile "/cookies.sqlite")) (user-error "Profile does not exist")))) - (overleaf--sqlite-select-firefox-overleaf-cookies cookie-file)) + (condition-case err + (overleaf--sqlite-select-firefox-overleaf-cookies cookie-file) + (sqlite-error + (condition-case _err + (let* ((temp-dir (make-temp-file "overleaf-firefox-cookies." t)) + (temp-cookie-file (expand-file-name "cookies.sqlite" temp-dir)) + (cookie-file-wal (concat cookie-file "-wal")) + (temp-cookie-file-wal (concat temp-cookie-file "-wal")) + (cookie-file-shm (concat cookie-file "-shm")) + (temp-cookie-file-shm (concat temp-cookie-file "-shm"))) + (unwind-protect + (progn + (copy-file cookie-file temp-cookie-file t t) + (when (file-exists-p cookie-file-wal) + (ignore-errors + (copy-file cookie-file-wal temp-cookie-file-wal t t))) + (when (file-exists-p cookie-file-shm) + (ignore-errors + (copy-file cookie-file-shm temp-cookie-file-shm t t))) + (overleaf--sqlite-select-firefox-overleaf-cookies temp-cookie-file)) + (ignore-errors (delete-directory temp-dir t)))) + (sqlite-error + (signal 'sqlite-error err)))))) (user-error "Sqlite not available!")))) (defvar overleaf-save-cookies (lambda (cookies)