The badge's current text (from chrome.action.getBadgeText).
The output about to be applied.
Whether the output should be written.
shouldApplyToBadge("5", { kind: "text", value: "5" }); // false — already shown
shouldApplyToBadge("5", { kind: "text", value: "6" }); // true
shouldApplyToBadge("", { kind: "clear" }); // false — already empty
export function shouldApplyToBadge(current: string, output: BadgeOutput): boolean {
switch (output.kind) {
case 'text':
return current !== output.value;
case 'clear':
return current !== '';
case 'animate':
return true;
}
}
Decides whether an output actually needs to be written to the badge, given the badge's current on-screen text. This is what prevents the open-with-results flicker: the toolbar badge persists across popup opens, so if it already shows the desired text (or is already empty), re-applying would blank-then-rewrite it (
BadgeAnimator.setTextclears before setting) — a visible flash.animatealways returnstruebecause a single text read can't tell whether the ellipsis is already cycling; the in-session isSameBadgeOutput guard handles repeatedanimateinstead.