Skip to content

Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)

Python

Update useBrowserTabIndicator.ts

Abi Raja1ac2ab33d9a3
diff --git a/frontend/src/hooks/useBrowserTabIndicator.ts b/frontend/src/hooks/useBrowserTabIndicator.ts
index aa8caddb..c04e6474 100644
--- a/frontend/src/hooks/useBrowserTabIndicator.ts
+++ b/frontend/src/hooks/useBrowserTabIndicator.ts
@@ -9,6 +9,57 @@ const DEFAULT_SETTINGS = {
favicon: "/favicon/main.png",
};
+const DEV_FAVICON_COLORS = {
+ default: "#22c55e",
+ coding: "#ef4444",
+};
+
+const getAugmentedFaviconDataUrl = (
+ baseUrl: string,
+ dotColor: string
+): Promise<string> =>
+ new Promise((resolve, reject) => {
+ const img = new Image();
+ img.crossOrigin = "anonymous";
+ img.onload = () => {
+ const size = Math.max(img.width, img.height, 64);
+ const canvas = document.createElement("canvas");
+ canvas.width = size;
+ canvas.height = size;
+ const ctx = canvas.getContext("2d");
+ if (!ctx) {
+ reject(new Error("Canvas not supported"));
+ return;
+ }
+
+ // Center the favicon in case it's not square
+ const x = (size - img.width) / 2;
+ const y = (size - img.height) / 2;
+ ctx.drawImage(img, x, y);
+
+ // Add a noticeable dev dot in the top-left corner
+ const dotRadius = Math.max(10, Math.round(size * 0.3));
+ const dotCx = size - dotRadius - Math.round(size * 0.04);
+ const dotCy = size - dotRadius - Math.round(size * 0.04);
+ ctx.beginPath();
+ ctx.arc(dotCx, dotCy, dotRadius, 0, Math.PI * 2);
+ ctx.fillStyle = dotColor;
+ ctx.fill();
+ ctx.lineWidth = Math.max(3, Math.round(size * 0.08));
+ ctx.strokeStyle = "#ffffff";
+ ctx.stroke();
+
+ resolve(canvas.toDataURL("image/png"));
+ };
+ img.onerror = () => reject(new Error("Failed to load favicon"));
+ img.src = baseUrl;
+ });
+
+const isDevHost = () => {
+ const host = window.location.hostname;
+ return host === "localhost" || host === "127.0.0.1" || host === "0.0.0.0";
+};
+
const useBrowserTabIndicator = (isCoding: boolean) => {
useEffect(() => {
const settings = isCoding ? CODING_SETTINGS : DEFAULT_SETTINGS;
@@ -18,7 +69,28 @@ const useBrowserTabIndicator = (isCoding: boolean) => {
"link[rel='icon']"
) as HTMLLinkElement | null;
if (faviconEl) {
- faviconEl.href = settings.favicon;
+ if (isDevHost()) {
+ let cancelled = false;
+ const dotColor = isCoding
+ ? DEV_FAVICON_COLORS.coding
+ : DEV_FAVICON_COLORS.default;
+ getAugmentedFaviconDataUrl(settings.favicon, dotColor)
+ .then((dataUrl) => {
+ if (!cancelled && faviconEl) {
+ faviconEl.href = dataUrl;
+ }
+ })
+ .catch(() => {
+ if (!cancelled && faviconEl) {
+ faviconEl.href = settings.favicon;
+ }
+ });
+ return () => {
+ cancelled = true;
+ };
+ } else {
+ faviconEl.href = settings.favicon;
+ }
}
// Set title