Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions packages/shared/src/favicon.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { describe, expect, it } from "@effect/vitest";

import {
explicitFaviconUrl,
faviconUrlForOrigin,
faviconUrlForPage,
toolActivityFaviconUrl,
} from "./favicon.ts";
import { faviconUrlForOrigin, toolActivityFaviconUrl } from "./favicon.ts";

describe("faviconUrlForOrigin", () => {
it.each([
Expand Down Expand Up @@ -46,12 +41,12 @@ describe("faviconUrlForOrigin", () => {
);
});

describe("faviconUrlForPage", () => {
describe("toolActivityFaviconUrl", () => {
it("uses the page origin instead of a third-party favicon service", () => {
expect(faviconUrlForPage("https://example.com/docs/page?q=1")).toBe(
expect(toolActivityFaviconUrl({ pageUrl: "https://example.com/docs/page?q=1" }, "light")).toBe(
"https://example.com/favicon.ico",
);
expect(faviconUrlForPage("http://localhost:5173/app")).toBe(
expect(toolActivityFaviconUrl({ pageUrl: "http://localhost:5173/app" }, "light")).toBe(
"http://localhost:5173/favicon.ico",
);
});
Expand Down Expand Up @@ -86,7 +81,17 @@ describe("faviconUrlForPage", () => {
});

it("accepts provider-supplied image URLs but rejects extension URLs", () => {
expect(explicitFaviconUrl("https://example.com/icon.png")).toBe("https://example.com/icon.png");
expect(explicitFaviconUrl("chrome-extension://example/_favicon/")).toBeNull();
expect(
toolActivityFaviconUrl(
{ pageUrl: "https://example.com/docs", faviconUrl: "https://example.com/icon.png" },
"light",
),
).toBe("https://example.com/icon.png");
expect(
toolActivityFaviconUrl(
{ pageUrl: "https://example.com/docs", faviconUrl: "chrome-extension://example/_favicon/" },
"light",
),
).toBe("https://example.com/favicon.ico");
});
});
4 changes: 2 additions & 2 deletions packages/shared/src/favicon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isPublicFaviconHost } from "./hostClassification.ts";
* conventional favicon and let the image element fall back to a browser glyph.
* Chrome-backed tools can pass their tab's explicit favicon URL separately.
*/
export function faviconUrlForPage(rawUrl: string | null | undefined, _size = 32): string | null {
function faviconUrlForPage(rawUrl: string | null | undefined, _size = 32): string | null {
if (!rawUrl || rawUrl.length > 4096) return null;
try {
const pageUrl = new URL(rawUrl);
Expand Down Expand Up @@ -40,7 +40,7 @@ function themedFaviconUrlForPage(
}

/** Accepts image URLs supplied by a trusted provider event. */
export function explicitFaviconUrl(rawUrl: string | null | undefined): string | null {
function explicitFaviconUrl(rawUrl: string | null | undefined): string | null {
if (!rawUrl || rawUrl.length > 4096) return null;
try {
const url = new URL(rawUrl);
Expand Down
Loading