From dfa0d5c084fe93d75d1ae545a88c66ee70e4718d Mon Sep 17 00:00:00 2001 From: Attila Lendvai Date: Thu, 14 Jul 2022 13:38:12 +0200 Subject: [PATCH 1/5] js/textareas: fail early and with a reasonable message ...when the contextmenu event handler is not triggered for whatever reason. --- javascript/context_menu.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/javascript/context_menu.js b/javascript/context_menu.js index d327496..c226bb3 100644 --- a/javascript/context_menu.js +++ b/javascript/context_menu.js @@ -1,13 +1,16 @@ /* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ (function(){ - var edit_msg = {}; + var edit_msg = null; function menuClicked(info, tab) { if (edit_msg) { var tab_port = chrome.tabs.connect(tab.id); edit_msg.pageUrl = info.pageUrl; handleContentMessages(edit_msg, tab_port); + edit_msg = null; + } else { + console.error("menuClicked called while edit_msg is null"); } } From 599a0e5b5785904df0fc2f60782b8f12f55a8c1a Mon Sep 17 00:00:00 2001 From: Attila Lendvai Date: Thu, 14 Jul 2022 13:39:00 +0200 Subject: [PATCH 2/5] js/contextmenu: rename menu_enabled -> menu_is_installed --- javascript/context_menu.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/javascript/context_menu.js b/javascript/context_menu.js index c226bb3..9d1af40 100644 --- a/javascript/context_menu.js +++ b/javascript/context_menu.js @@ -14,11 +14,10 @@ } } - - var menu_enabled = false; + var menu_is_installed = false; function enableContextMenu() { - if (!menu_enabled) { + if (!menu_is_installed) { chrome.contextMenus.removeAll(); chrome.contextMenus.create({ title: "Edit with Emacs", @@ -27,13 +26,13 @@ menuClicked(info, tab); } }); - menu_enabled = true; + menu_is_installed = true; } } function disableContextMenu() { chrome.contextMenus.removeAll(); - menu_enabled = false; + menu_is_installed = false; } // Initialize the context menu based on stored options. From 038fc9084b813fa552ab3ca285aaf09eeeaf5a74 Mon Sep 17 00:00:00 2001 From: Attila Lendvai Date: Thu, 14 Jul 2022 13:40:57 +0200 Subject: [PATCH 3/5] js/xmlcomms: fail early with an assert when no text in message --- javascript/xmlcomms.js | 1 + 1 file changed, 1 insertion(+) diff --git a/javascript/xmlcomms.js b/javascript/xmlcomms.js index 4489f74..9e2b519 100644 --- a/javascript/xmlcomms.js +++ b/javascript/xmlcomms.js @@ -102,6 +102,7 @@ chrome.commands.onCommand.addListener(function(command) { function handleContentMessages(msg, tab_port) { console.log("handleContentMessages called:"+JSON.stringify(msg)); + console.assert(msg.text); var cmd = msg.msg; var id = msg.id; var text = msg.text; From 0c86b92afcd06f20c5350b74baf44a1f86244d7d Mon Sep 17 00:00:00 2001 From: Attila Lendvai Date: Thu, 14 Jul 2022 13:42:21 +0200 Subject: [PATCH 4/5] Added more logging while tracking down an issue --- javascript/context_menu.js | 1 + javascript/textareas.js | 7 +++++++ javascript/xmlcomms.js | 2 +- servers/edit-server.el | 6 +++++- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/javascript/context_menu.js b/javascript/context_menu.js index 9d1af40..2de3c12 100644 --- a/javascript/context_menu.js +++ b/javascript/context_menu.js @@ -7,6 +7,7 @@ if (edit_msg) { var tab_port = chrome.tabs.connect(tab.id); edit_msg.pageUrl = info.pageUrl; + console.debug("menuClicked with edit_msg:", edit_msg); handleContentMessages(edit_msg, tab_port); edit_msg = null; } else { diff --git a/javascript/textareas.js b/javascript/textareas.js index 6fb0d93..d2ecc3b 100644 --- a/javascript/textareas.js +++ b/javascript/textareas.js @@ -263,6 +263,7 @@ function sendTextArea(text_tracker) { edit_msg.msg = "edit"; edit_msg.text = text_tracker.getContent(); edit_msg.id = text_tracker.edit_id; + console.debug("sendTextArea: sending message:", edit_msg); port.postMessage(edit_msg); } @@ -429,17 +430,21 @@ browser_runtime.onConnect.addListener(function(iport) { iport.onMessage.addListener(localMessageHandler); }); +console.debug("About to fetch our configuration from the background process"); + /* To start the whole process off we first need to fetch our configuration from the background process. */ port.postMessage({msg: "config"}); +console.debug("About to install contextmenu event listener on document"); // Inform the background process whenever the user opens // the context menu on an editable element. document.addEventListener("contextmenu", (function(event) { var elem = event.srcElement; + console.debug("contextmenu event called on elem: ", elem); if (elem && elem.getAttribute("edit_id")) { var edit_msg = getEmptyMessage(); edit_msg.msg = "edit"; @@ -452,3 +457,5 @@ document.addEventListener("contextmenu", (function(event) { browser_sendMessage(request); } })); + +console.debug("Edit with Emacs has finished initializing"); diff --git a/javascript/xmlcomms.js b/javascript/xmlcomms.js index 9e2b519..2fa9f91 100644 --- a/javascript/xmlcomms.js +++ b/javascript/xmlcomms.js @@ -101,7 +101,7 @@ chrome.commands.onCommand.addListener(function(command) { // Package up the text to be edited and send it to the edit server function handleContentMessages(msg, tab_port) { - console.log("handleContentMessages called:"+JSON.stringify(msg)); + console.debug("handleContentMessages called:", msg); console.assert(msg.text); var cmd = msg.msg; var id = msg.id; diff --git a/servers/edit-server.el b/servers/edit-server.el index 7accc16..aa1c4e4 100644 --- a/servers/edit-server.el +++ b/servers/edit-server.el @@ -392,6 +392,7 @@ non-nil, then STRING is also echoed to the message line." ;; data in the buffer and process it in different phases, which ;; requires us to keep track of the processing state. (with-current-buffer (process-buffer proc) + (edit-server-log proc "Got HTTP request string of length `%s'" (length string)) (insert string) (setq edit-server-received (+ edit-server-received (string-bytes string))) @@ -415,6 +416,7 @@ non-nil, then STRING is also echoed to the message line." (save-excursion (goto-char (point-min)) (when (re-search-forward "^Content-Length:\\s-+\\([0-9]+\\)" nil t) + (edit-server-log proc "Found Content-Length: %s" (match-string 1)) (setq edit-server-content-length (string-to-number (match-string 1))))) ;; look for "x-url" header @@ -434,6 +436,7 @@ non-nil, then STRING is also echoed to the message line." (when (re-search-forward "\\(\r?\n\\)\\{2\\}" nil t) ;; HTTP headers are pure ASCII (1 char = 1 byte), so we can subtract ;; the buffer position from the count of received bytes + (edit-server-log proc "Found body offset at: %s" (match-end 0)) (setq edit-server-received (- edit-server-received (- (match-end 0) (point-min)))) ;; discard headers - keep only HTTP content in buffer @@ -540,7 +543,8 @@ and save the network process for the final call back" (when existing-buffer (kill-ring-save (point-min) (point-max))) - (edit-server-log proc "copying new data into buffer") + (edit-server-log proc "copying new data into buffer, length: %s" + (- (point-max) (point-min))) (copy-to-buffer buffer (point-min) (point-max)) (with-current-buffer buffer From 43eabb6f8c87d77d237f5f3c5bbc10e9d3916dbf Mon Sep 17 00:00:00 2001 From: Attila Lendvai Date: Thu, 14 Jul 2022 13:47:01 +0200 Subject: [PATCH 5/5] Fix some typos This is a rebase of PR 148. Signed-off-by: Christian Krause --- fancy-settings/source/i18n.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fancy-settings/source/i18n.js b/fancy-settings/source/i18n.js index dfb9024..ee57181 100755 --- a/fancy-settings/source/i18n.js +++ b/fancy-settings/source/i18n.js @@ -43,12 +43,12 @@ this.i18n = { "en": "Edit with Emacs is an extension that allows you to edit textareas and other editable text elements\ of a web-page with your favourite editor. For this to work you need to be running an \"edit server\"\ on your local machine. This is because extensions in Chrome(ium) cannot directly start new programs. For Emacs users \ - it is recommended you use the use supplied native edit-server.el.\ - Alternativley you can track the latest version through the MELPA\ + it is recommended you use the supplied native edit-server.el.\ + Alternativeley you can track the latest version through the MELPA\ package archive.\

\

\ - Save the file to somewhere visible to your your Emacs load-path (~/.emacs.d/lisp is popular) and add the following\ + Save the file to somewhere visible to your Emacs load-path (~/.emacs.d/lisp is popular) and add the following\ to your .emacs:\

\
\