From b28241dbf23b627e252348aa0445e4e7befe01fc Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 6 Sep 2020 14:36:43 -0400 Subject: [PATCH] Fix error handling for screenshot captures (#777) --- ext/bg/js/backend.js | 11 +++++++++-- ext/mixed/js/display.js | 7 ++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index 2c741dd7..a9ef4ce4 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -537,8 +537,15 @@ class Backend { } const windowId = sender.tab.windowId; - return new Promise((resolve) => { - chrome.tabs.captureVisibleTab(windowId, options, (dataUrl) => resolve(dataUrl)); + return new Promise((resolve, reject) => { + chrome.tabs.captureVisibleTab(windowId, options, (dataUrl) => { + const e = chrome.runtime.lastError; + if (e) { + reject(new Error(e.message)); + } else { + resolve(dataUrl); + } + }); }); } diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index ce7a4385..4c058948 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -1049,9 +1049,11 @@ class Display extends EventDispatcher { const details = {}; if (this._noteUsesScreenshot(mode)) { - const screenshot = await this._getScreenshot(); - if (screenshot) { + try { + const screenshot = await this._getScreenshot(); details.screenshot = screenshot; + } catch (e) { + // NOP } } @@ -1155,7 +1157,6 @@ class Display extends EventDispatcher { const {format, quality} = this._options.anki.screenshot; const dataUrl = await api.screenshotGet({format, quality}); - if (!dataUrl || dataUrl.error) { return; } return {dataUrl, format}; } finally {