-
Notifications
You must be signed in to change notification settings - Fork 79
Description
Proposal
I propose to implement a simple check for the length of input to setBadgeText(). I believe the API should limit the number of bytes in the input string, not the character or render width, since those checks are more complex and depend on font rendering and particular style of UI which would differ between browsers.
Background
Extensions can set a custom badge (text) which is displayed over the extension action button in browser chrome. This UI element is very small and can display only a few characters or symbols or emojis, may be a few words written in Chinese or Korean. Despite clear visual limitations, setBadgeText() method accepts inputs of unbounded length.
- Extensions can (accidentally) create long strings and consume the browser resources while all performance profilers would miss-attribute this memory usage to browser process.
- Unlikely, but theoretically possible that extensions would use badge to store data. This may be convenient, since the actual storage APIs impose per-item limit and do not natively support keying storage by Tab ID and Window ID.
Considerations
- Limit should be very permissive to enable extension developers' creativity.
- Valid strings may contain multi-byte characters, including 4-byte emojis and emojis combined with 1-byte zero-width joiner (ZWJ). A single emoji rendered can be 19 bytes long if it combines four 4-byte emojis with ZWJ between them. Here is a concrete example of 19-byte string rendered by Chrome and Firefox as a single character. Only two such emojis fit in current Chrome UI for total length of 38 bytes.
- Future or alternative browser UI revisions might be able to display more characters. Current Chrome UI can comfortably display only 4 digit numbers or 12 dots.
To ensure broad compatibility, we should introduce a histogram tracking the length of real-world badge strings.
Next actions
- Please review histogram buckets in Chromium CL
- Let's discuss this issue during meeting on 2026-03-12 (Agenda discussion for public meeting on 2026-03-12 #957)