diff options
| -rw-r--r-- | ext/bg/js/backend.js | 46 | ||||
| -rw-r--r-- | ext/bg/js/search.js | 2 | ||||
| -rw-r--r-- | ext/fg/js/popup-window.js | 2 | ||||
| -rw-r--r-- | ext/mixed/js/display.js | 3 | 
4 files changed, 31 insertions, 22 deletions
| diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index fd90a220..465c8137 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -465,11 +465,7 @@ class Backend {          return results;      } -    async _onApiInjectAnkiNoteMedia({timestamp, definitionDetails, audioDetails, screenshotDetails, clipboardDetails}, sender) { -        if (isObject(screenshotDetails)) { -            const {id: tabId, windowId} = (sender && sender.tab ? sender.tab : {}); -            screenshotDetails = Object.assign({}, screenshotDetails, {tabId, windowId}); -        } +    async _onApiInjectAnkiNoteMedia({timestamp, definitionDetails, audioDetails, screenshotDetails, clipboardDetails}) {          return await this._injectAnkNoteMedia(              this._anki,              timestamp, @@ -1494,23 +1490,21 @@ class Backend {      }      async _checkTabUrl(tabId, urlPredicate) { -        const tab = await new Promise((resolve) => { -            chrome.tabs.get( -                tabId, -                (result) => { resolve(chrome.runtime.lastError ? null : result); } -            ); -        }); -        if (tab === null) { return null; } +        let tab; +        try { +            tab = await this._getTabById(tabId); +        } catch (e) { +            return null; +        }          const url = await this._getTabUrl(tabId);          const isValidTab = urlPredicate(url);          return isValidTab ? tab : null;      } -    async _getScreenshot(windowId, tabId, frameId, format, quality) { -        if (typeof windowId !== 'number') { -            throw new Error('Invalid window ID'); -        } +    async _getScreenshot(tabId, frameId, format, quality) { +        const tab = await this._getTabById(tabId); +        const {windowId} = tab;          let token = null;          try { @@ -1636,8 +1630,8 @@ class Backend {      }      async _injectAnkNoteScreenshot(ankiConnect, timestamp, definitionDetails, details) { -        const {windowId, tabId, frameId, format, quality} = details; -        const dataUrl = await this._getScreenshot(windowId, tabId, frameId, format, quality); +        const {tabId, frameId, format, quality} = details; +        const dataUrl = await this._getScreenshot(tabId, frameId, format, quality);          const {mediaType, data} = this._getDataUrlInfo(dataUrl);          const extension = this._mediaUtility.getFileExtensionFromImageMediaType(mediaType); @@ -1954,4 +1948,20 @@ class Backend {              }          }));      } + +    _getTabById(tabId) { +        return new Promise((resolve, reject) => { +            chrome.tabs.get( +                tabId, +                (result) => { +                    const e = chrome.runtime.lastError; +                    if (e) { +                        reject(new Error(e.message)); +                    } else { +                        resolve(result); +                    } +                } +            ); +        }); +    }  } diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js index dbc679b1..a786b0bf 100644 --- a/ext/bg/js/search.js +++ b/ext/bg/js/search.js @@ -24,7 +24,7 @@  class DisplaySearch extends Display {      constructor(tabId, frameId, japaneseUtil, documentFocusController, hotkeyHandler) { -        super('search', tabId, frameId, japaneseUtil, documentFocusController, hotkeyHandler); +        super(tabId, frameId, 'search', japaneseUtil, documentFocusController, hotkeyHandler);          this._searchButton = document.querySelector('#search-button');          this._queryInput = document.querySelector('#search-textbox');          this._introElement = document.querySelector('#intro'); diff --git a/ext/fg/js/popup-window.js b/ext/fg/js/popup-window.js index 9398c287..5fa0c647 100644 --- a/ext/fg/js/popup-window.js +++ b/ext/fg/js/popup-window.js @@ -85,7 +85,7 @@ class PopupWindow extends EventDispatcher {          return (this._popupTabId !== null && await api.isTabSearchPopup(this._popupTabId));      } -    setVisibleOverride(_value, _priority) { +    async setVisibleOverride(_value, _priority) {          return null;      } diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 69cc3d42..c8b7b14b 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -1539,10 +1539,9 @@ class Display extends EventDispatcher {          } = options;          const timestamp = Date.now(); -        const screenshotFrameId = this._contentOriginFrameId;          const definitionDetails = this._getDefinitionDetailsForNote(definition);          const audioDetails = (mode !== 'kanji' && this._ankiNoteBuilder.containsMarker(fields, 'audio') ? {sources, customSourceUrl, customSourceType} : null); -        const screenshotDetails = (this._ankiNoteBuilder.containsMarker(fields, 'screenshot') ? {frameId: screenshotFrameId, format, quality} : null); +        const screenshotDetails = (this._ankiNoteBuilder.containsMarker(fields, 'screenshot') ? {tabId: this._contentOriginTabId, frameId: this._contentOriginFrameId, format, quality} : null);          const clipboardDetails = {              image: this._ankiNoteBuilder.containsMarker(fields, 'clipboard-image'),              text: this._ankiNoteBuilder.containsMarker(fields, 'clipboard-text') |