From 77a1e531c23bd325b43868e1499d95b4abc6ef40 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 26 Aug 2020 11:38:50 +0200 Subject: [PATCH] Ensure that the `sourceEventType` parameter is actually optional in `PDFViewerApplication.{download, save}` (PR 12248 follow-up) Without these changes, clicking on the "Open With Different Viewer"-button on the Firefox fallback bar won't actually do anything and the following is printed in the web-console: ``` Uncaught TypeError: (destructured parameter) is undefined download resource://pdf.js/web/viewer.js:956 response resource://pdf.js/web/viewer.js:1054 listener resource://pdf.js/web/viewer.js:11891 viewer.js:956:1 ``` Furthermore, this patch also fixes `PDFViewerApplication.fallback` to pass in an explicit `sourceEventType` when triggering downloading. While this, on its own, would obviously have been sufficient to fix the bug described above, it seems wrong to outright break backwards compatibility of any older `PDFViewerApplication.download` calls. --- web/app.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web/app.js b/web/app.js index 1ba89133d..0ebc72663 100644 --- a/web/app.js +++ b/web/app.js @@ -874,7 +874,7 @@ const PDFViewerApplication = { ); }, - download({ sourceEventType = "download" }) { + download({ sourceEventType = "download" } = {}) { function downloadByUrl() { downloadManager.downloadUrl(url, filename); } @@ -907,7 +907,7 @@ const PDFViewerApplication = { .catch(downloadByUrl); // Error occurred, try downloading with the URL. }, - save({ sourceEventType = "download" }) { + save({ sourceEventType = "download" } = {}) { if (this._saveInProgress) { return; } @@ -988,7 +988,7 @@ const PDFViewerApplication = { if (!download) { return; } - PDFViewerApplication.download(); + PDFViewerApplication.download({ sourceEventType: "download" }); } ); },