From 11e58d616cffbadc5a0c6ab72e5fc803f8c4e70b Mon Sep 17 00:00:00 2001 From: Cashew <52880648+cashewnuttynuts@users.noreply.github.com> Date: Tue, 9 Apr 2024 17:52:37 +0900 Subject: Fix duplicated title (#735) * fix duplicated title * add comment * fix lint * change to use action.default_title --------- Co-authored-by: StefanVukovic99 --- ext/js/background/backend.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js index 6cae9cea..569cb53d 100644 --- a/ext/js/background/backend.js +++ b/ext/js/background/backend.js @@ -253,7 +253,7 @@ export class Backend { this._prepareInternalSync(); this._permissions = await getAllPermissions(); - this._defaultBrowserActionTitle = await this._getBrowserIconTitle(); + this._defaultBrowserActionTitle = this._getBrowserIconTitle(); this._badgePrepareDelayTimer = setTimeout(() => { this._badgePrepareDelayTimer = null; this._updateBadge(); @@ -1616,15 +1616,18 @@ export class Backend { } /** - * @returns {Promise} + * Returns the action's default title. + * @throws {Error} + * @returns {string} */ _getBrowserIconTitle() { - return ( - isObjectNotArray(chrome.action) && - typeof chrome.action.getTitle === 'function' ? - new Promise((resolve) => { chrome.action.getTitle({}, resolve); }) : - Promise.resolve('') - ); + const manifest = /** @type {chrome.runtime.ManifestV3} */ (chrome.runtime.getManifest()); + const action = manifest.action; + if (typeof action === 'undefined') { throw new Error('Failed to find action'); } + const defaultTitle = action.default_title; + if (typeof defaultTitle === 'undefined') { throw new Error('Failed to find default_title'); } + + return defaultTitle; } /** -- cgit v1.2.3