From 8b3b5424471a44e0784b69b638c9093afd4e031b Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 31 Dec 2020 14:34:16 +0100 Subject: [PATCH] Ensure that the "pdf.js.response" event listener, in `FirefoxCom.request`, actually applies to the current `Text` node Given that the event listener is registered on the document, there could in *theory* be more than one of these listeners present at any one time. In practice this doesn't currently happen, since all of the `actions` invoked in [`PdfStreamConverter.jsm`](https://searchfox.org/mozilla-central/rev/bfbacfb6a4efd98247e83d3305e912ca4f7e106a/toolkit/components/pdfjs/content/PdfStreamConverter.jsm#933-952) are *synchronous* methods. However, there's no guarantee that this will always be the case, and it's easy enough to prevent any future issues here by simply registering the "pdf.js.response" event listener on the `Text` node instead. This works since, as can be seen in [`PdfStreamConverter.jsm`](https://searchfox.org/mozilla-central/rev/bfbacfb6a4efd98247e83d3305e912ca4f7e106a/toolkit/components/pdfjs/content/PdfStreamConverter.jsm#919,943), the event is dispatched on the element itself rather than the document. --- web/firefoxcom.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/web/firefoxcom.js b/web/firefoxcom.js index f65e9bc7e..ecb3095d7 100644 --- a/web/firefoxcom.js +++ b/web/firefoxcom.js @@ -64,12 +64,11 @@ const FirefoxCom = (function FirefoxComClosure() { request(action, data, callback) { const request = document.createTextNode(""); if (callback) { - document.addEventListener( + request.addEventListener( "pdf.js.response", event => { - const node = event.target; const response = event.detail.response; - node.remove(); + event.target.remove(); callback(response); },