async function updateMatchingPasswordsCount(tabId, forceRefresh = false) {
    if (badgeCache.isRefreshing) {
        return;
    }

    try {
        if (forceRefresh || Date.now() > badgeCache.expires) {
            badgeCache.isRefreshing = true;

            let files = [];
            let settings = await getFullSettings();
            if (!settings.hideBadge) {
                let response = await hostAction(settings, "list");
                if (response.status != "ok") {
                    throw new Error(JSON.stringify(response));
                }
                files = response.data.files;
            }

            const CACHE_TTL_MS = 60 * 1000;
            badgeCache = {
                files: files,
                settings: settings,
                expires: Date.now() + CACHE_TTL_MS,
                isRefreshing: false,
            };
        }

        try {
            const tab = await chrome.tabs.get(tabId);
            badgeCache.settings.origin = new BrowserpassURL(tab.url).origin;
        } catch (e) {
            throw new Error(`Unable to determine domain of the tab with id ${tabId}`);
        }

        // Compute badge counter
        const files = helpers.ignoreFiles(badgeCache.files, badgeCache.settings);
        const logins = helpers.prepareLogins(files, badgeCache.settings);
        const matchedPasswordsCount = logins.reduce(
            (acc, login) => acc + (login.recent.count || login.inCurrentHost ? 1 : 0),
            0
        );

        // Set badge for the current tab
        chrome.action.setBadgeText({
            text: "" + (matchedPasswordsCount || ""),
            tabId: tabId,
        });
    } catch (e) {
        badgeCache.isRefreshing = false;
        console.log(e);
    }
}
Set badge text with the number of matching password entries

@since 3.0.0

@param int  tabId Tab id
@param bool forceRefresh force invalidate cache
@return void