From 57999cf5e305e818d336db39956a4c06b0df2243 Mon Sep 17 00:00:00 2001 From: Elbert Alias <77259+AliasIO@users.noreply.github.com> Date: Tue, 7 Dec 2021 12:59:02 +1100 Subject: [PATCH] Make downloads permission optional --- src/drivers/webextension/js/popup.js | 14 ++++++++++---- src/drivers/webextension/manifest.json | 6 ++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/drivers/webextension/js/popup.js b/src/drivers/webextension/js/popup.js index 2d29df8b1..ef096ee69 100644 --- a/src/drivers/webextension/js/popup.js +++ b/src/drivers/webextension/js/popup.js @@ -900,7 +900,7 @@ const Popup = { i18n() }, - downloadCsv(event) { + async downloadCsv(event) { event.preventDefault() const { csv, filename } = getCsv() @@ -909,11 +909,17 @@ const Popup = { new Blob([csv.join('\n')], { type: 'text/csv;charset=utf-8' }) ) - chrome.downloads.download({ - url: file, - filename, + const granted = await promisify(chrome.permissions, 'request', { + permissions: ['downloads'], }) + if (granted) { + chrome.downloads.download({ + url: file, + filename, + }) + } + return false }, } diff --git a/src/drivers/webextension/manifest.json b/src/drivers/webextension/manifest.json index 6e8e19acf..d091c2311 100644 --- a/src/drivers/webextension/manifest.json +++ b/src/drivers/webextension/manifest.json @@ -73,9 +73,11 @@ "tabs", "webRequest", "webNavigation", - "downloads", "http://*/*", "https://*/*" ], + "optional_permissions": [ + "downloads" + ], "content_security_policy": "script-src 'self'; object-src 'self'" -} \ No newline at end of file +}