diff options
Diffstat (limited to 'ext/js/background/offscreen-proxy.js')
-rw-r--r-- | ext/js/background/offscreen-proxy.js | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/ext/js/background/offscreen-proxy.js b/ext/js/background/offscreen-proxy.js index 77f5448a..555c3abc 100644 --- a/ext/js/background/offscreen-proxy.js +++ b/ext/js/background/offscreen-proxy.js @@ -16,12 +16,17 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -import {isObject} from '../core/utilities.js'; import {ExtensionError} from '../core/extension-error.js'; +import {isObject} from '../core/utilities.js'; import {ArrayBufferUtil} from '../data/sandbox/array-buffer-util.js'; export class OffscreenProxy { - constructor() { + /** + * @param {import('../extension/web-extension.js').WebExtension} webExtension + */ + constructor(webExtension) { + /** @type {import('../extension/web-extension.js').WebExtension} */ + this._webExtension = webExtension; /** @type {?Promise<void>} */ this._creatingOffscreen = null; } @@ -76,16 +81,9 @@ export class OffscreenProxy { * @param {import('offscreen').ApiMessage<TMessageType>} message * @returns {Promise<import('offscreen').ApiReturn<TMessageType>>} */ - sendMessagePromise(message) { - return new Promise((resolve, reject) => { - chrome.runtime.sendMessage(message, (response) => { - try { - resolve(this._getMessageResponseResult(response)); - } catch (error) { - reject(error); - } - }); - }); + async sendMessagePromise(message) { + const response = await this._webExtension.sendMessagePromise(message); + return this._getMessageResponseResult(/** @type {import('core').Response<import('offscreen').ApiReturn<TMessageType>>} */ (response)); } /** |