From ad94a56e573553f3c66e8fcccff3042544faeb1b Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Wed, 20 Dec 2023 00:43:41 -0500 Subject: Add Offscreen.prepare for constructor side effects (#402) --- ext/js/background/offscreen-main.js | 7 ++++--- ext/js/background/offscreen.js | 8 +++++--- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'ext/js') diff --git a/ext/js/background/offscreen-main.js b/ext/js/background/offscreen-main.js index f85908bd..aac5b8f2 100644 --- a/ext/js/background/offscreen-main.js +++ b/ext/js/background/offscreen-main.js @@ -19,8 +19,9 @@ import {Offscreen} from './offscreen.js'; /** Entry point. */ -async function main() { - new Offscreen(); +function main() { + const offscreen = new Offscreen(); + offscreen.prepare(); } -await main(); +main(); diff --git a/ext/js/background/offscreen.js b/ext/js/background/offscreen.js index bcbcda6b..d1cf3384 100644 --- a/ext/js/background/offscreen.js +++ b/ext/js/background/offscreen.js @@ -68,13 +68,15 @@ export class Offscreen { ])); /* eslint-enable no-multi-spaces */ - const onMessage = this._onMessage.bind(this); - chrome.runtime.onMessage.addListener(onMessage); - /** @type {?Promise} */ this._prepareDatabasePromise = null; } + /** */ + prepare() { + chrome.runtime.onMessage.addListener(this._onMessage.bind(this)); + } + /** @type {import('offscreen').MessageHandler<'clipboardGetTextOffscreen', true>} */ async _getTextHandler({useRichText}) { return await this._clipboardReader.getText(useRichText); -- cgit v1.2.3