Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[PM-20210] Expand badge API #14801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 41 commits into
base: main
Choose a base branch
Loading
from

Conversation

coroiu
Copy link
Contributor

@coroiu coroiu commented May 15, 2025

🎟️ Tracking

📔 Objective

  • Recreate the Badge API using a new non-monolithic design
  • Migrate previously entangled domain-specific logic over to separate service using the new API and move that code over to their ownership
    • Autofill badge number
    • Auth status icon

🆕 Updates

The previous implementation didn't handle tab ids which resulted in a bug where some separate windows which were actually interpreted as tabs by the browser caused the badge autofill number to disappear. An example of this is if you opened the Bitwarden popout:

badgebug

The BadgeService now has full support for tabs meaning that you can now set tab-specific badge states. The autofill implementation has been completely rewritten to take advantage of this.

In comparison to the old badge-listener the new BadgeService does not need to be updated every time the user changes active tabs, instead the browser will keep track of all states for us and automatically change the badge whenever a different tab is displayed. This means that the new BadgeService will not have to wake the service worker for active tab changes.

📸 Screenshots

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

@coroiu coroiu requested review from a team as code owners May 15, 2025 14:38
Copy link

codecov bot commented May 15, 2025

Codecov Report

Attention: Patch coverage is 45.97156% with 114 lines in your changes missing coverage. Please review.

Project coverage is 36.91%. Comparing base (8b0e8b9) to head (b41b491).

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...utofill/services/autofill-badge-updater.service.ts 7.93% 58 Missing ⚠️
...ps/browser/src/platform/badge/badge-browser-api.ts 7.50% 37 Missing ⚠️
...auth/services/auth-status-badge-updater.service.ts 35.00% 13 Missing ⚠️
apps/browser/src/background/main.background.ts 44.44% 5 Missing ⚠️
apps/browser/src/platform/badge/badge.service.ts 98.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14801      +/-   ##
==========================================
+ Coverage   36.86%   36.91%   +0.04%     
==========================================
  Files        3228     3237       +9     
  Lines       93388    93506     +118     
  Branches    14056    14064       +8     
==========================================
+ Hits        34426    34515      +89     
- Misses      57536    57565      +29     
  Partials     1426     1426              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

apps/browser/src/platform/badge/badge.service.spec.ts Outdated Show resolved Hide resolved
Copy link
Contributor

github-actions bot commented May 15, 2025

Logo
Checkmarx One – Scan Summary & Details877b4fb9-29a6-4ef9-9f78-f8bae05f4012

New Issues (3)

Checkmarx found the following issues in this Pull Request

Severity Issue Source File / Package Checkmarx Insight
MEDIUM CVE-2025-6555 Npm-electron-36.4.0
detailsRecommended version: 37.0.0
Description: Use after free in Animation in Google Chrome prior to 138.0.7204.49 allowed a remote attacker to potentially exploit heap corruption via a crafted ...
Attack Vector: NETWORK
Attack Complexity: LOW

ID: vxWToP7%2BztCUEgE6qxdNHh0U3E5VwXMtI67IbE8wu70%3D
Vulnerable Package
MEDIUM CVE-2025-6556 Npm-electron-36.4.0
detailsDescription: Insufficient policy enforcement in Loader in Google Chrome prior to 138.0.7204.49 allowed a remote attacker to bypass content security policy via a...
Attack Vector: NETWORK
Attack Complexity: LOW

ID: F5WLzChehcR34M4v%2BdOAU3aaAbUQckfRDeq9mlzACMw%3D
Vulnerable Package
MEDIUM CVE-2025-6557 Npm-electron-36.4.0
detailsDescription: Insufficient data validation in DevTools in Google Chrome on Windows prior to 138.0.7204.49 allowed a remote attacker who convinced a user to engag...
Attack Vector: NETWORK
Attack Complexity: LOW

ID: vlON6cyJbs%2FhkavGFl0hycsJrQJ46FXFsaIkLk89ilE%3D
Vulnerable Package

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 auth changes looks good, cool stuff goin on here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Auth changes look good! Excited to see this work go in.

coroiu added 2 commits June 25, 2025 09:21
The service assumes that the first emission from the state will be an empty one and discards it
(techincally it just doesn't act on it because pairwise requires a minimum two emissions). This
caused issues when a service is able to update the state before the observable got a change to
properly initialize. To fix this we simply force an empty emission before anything else,
that way we will always react to the emission from the state provider (because that would end up
being the second emission). We then use distinctUntilChanged to avoid unecessarily acting on
an empty state.
Copy link

Copy link
Contributor

@JaredSnider-Bitwarden JaredSnider-Bitwarden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, the new implementation is nice 🏅 . LGTM!

@jprusik
Copy link
Contributor

jprusik commented Jun 27, 2025

Comment on lines +113 to +133
BrowserApi.addListener(chrome.tabs.onReplaced, async (addedTabId, removedTabId) => {
const newTab = await BrowserApi.getTab(addedTabId);
if (!newTab) {
this.logService.warning(
`Tab replaced event received but new tab not found (id: ${addedTabId})`,
);
return;
}

this.tabReplaced$.next({
removedTabId,
addedTab: newTab,
});
});
BrowserApi.addListener(chrome.tabs.onUpdated, (_, changeInfo, tab) => {
if (changeInfo.url) {
this.tabUpdated$.next(tab);
}
});
BrowserApi.addListener(chrome.tabs.onRemoved, (tabId, _) => this.tabRemoved$.next(tabId));
}
Copy link
Contributor

@jprusik jprusik Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hrm; is adding parallel listeners to the tab going to increase overhead/affect performance? Certainly cleaner code-wise, just wondering if we'd run into issues implementing this pattern for other tab event side-effects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.