Skip to content

Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.

feat: add comprehensive test coverage for cookie management, sniffer functionality, and manifest permissions; enhance UI toggle elements

Tonhofbc1d7159c6a
diff --git a/browser-extension/chrome/tests/action-click.test.mjs b/browser-extension/chrome/tests/action-click.test.mjs
index 14634fe0..44b3e767 100644
--- a/browser-extension/chrome/tests/action-click.test.mjs
+++ b/browser-extension/chrome/tests/action-click.test.mjs
@@ -28,7 +28,7 @@ test("clears the previous badge and shows success feedback after a successful se
assert.equal(result, true);
assert.deepEqual(calls, [
["clear", 12],
- ["send", { type: "enqueue", url: "https://example.com/watch?v=123" }],
+ ["send", { type: "enqueue", url: "https://example.com/watch?v=123", protocolVersion: 1 }],
["success", 12],
]);
});
@@ -150,3 +150,62 @@ test("does not show success feedback when native messaging throws", async () =>
["error", { code: "HOST_MISSING", message: "host missing", url: "https://example.com/post/xyz" }],
]);
});
+
+test("falls back to scheme handler when native messaging throws and scheme succeeds", async () => {
+ const calls = [];
+
+ const result = await handleSupportedActionClick({
+ tabId: 42,
+ url: "https://example.com/video/abc",
+ sendNativeMessage: async () => {
+ throw new Error("host missing");
+ },
+ clearBadge: async (tabId) => {
+ calls.push(["clear", tabId]);
+ },
+ showSuccessBadge: async (tabId) => {
+ calls.push(["success", tabId]);
+ },
+ openErrorPage: async (details) => {
+ calls.push(["error", details]);
+ },
+ mapChromeErrorCode: () => "HOST_MISSING",
+ openSchemeUrl: async (url) => {
+ calls.push(["scheme", url]);
+ return { ok: true, schemeUrl: `omniget://${url}` };
+ },
+ });
+
+ assert.equal(result, true);
+ assert.deepEqual(calls, [
+ ["clear", 42],
+ ["scheme", "https://example.com/video/abc"],
+ ["success", 42],
+ ]);
+});
+
+test("opens error page when both native messaging and scheme fallback fail", async () => {
+ const calls = [];
+
+ const result = await handleSupportedActionClick({
+ tabId: 5,
+ url: "https://example.com/v/xyz",
+ sendNativeMessage: async () => {
+ throw new Error("host missing");
+ },
+ clearBadge: async () => {},
+ showSuccessBadge: async () => {
+ calls.push(["success"]);
+ },
+ openErrorPage: async (details) => {
+ calls.push(["error", details]);
+ },
+ mapChromeErrorCode: () => "HOST_MISSING",
+ openSchemeUrl: async () => ({ ok: false, reason: "tabs-update-failed" }),
+ });
+
+ assert.equal(result, false);
+ assert.deepEqual(calls, [
+ ["error", { code: "HOST_MISSING", message: "host missing", url: "https://example.com/v/xyz" }],
+ ]);
+});
diff --git a/browser-extension/chrome/tests/blocked-hosts.test.mjs b/browser-extension/chrome/tests/blocked-hosts.test.mjs
new file mode 100644
index 00000000..5d70bec9
--- /dev/null
+++ b/browser-extension/chrome/tests/blocked-hosts.test.mjs
@@ -0,0 +1,93 @@
+import test from "node:test";
+import assert from "node:assert/strict";
+import {
+ DEFAULT_BLOCKED_HOSTS,
+ isHostBlocked,
+ isUrlHostBlocked,
+ mergeBlocklists,
+ normalizeBlocklist,
+ USER_BLOCKED_HOSTS_KEY,
+} from "../src/blocked-hosts.js";
+
+test("USER_BLOCKED_HOSTS_KEY is the documented storage key", () => {
+ assert.equal(USER_BLOCKED_HOSTS_KEY, "userBlockedHosts");
+});
+
+test("DEFAULT_BLOCKED_HOSTS is non-empty and frozen", () => {
+ assert.ok(DEFAULT_BLOCKED_HOSTS.length > 0);
+ assert.equal(Object.isFrozen(DEFAULT_BLOCKED_HOSTS), true);
+});
+
+test("normalizeBlocklist lowercases and strips wildcards and leading dots", () => {
+ const out = normalizeBlocklist([" Ads.EXAMPLE.com ", "*.tracker.io", ".beacon.net"]);
+
+ assert.deepEqual(out, ["ads.example.com", "tracker.io", "beacon.net"]);
+});
+
+test("normalizeBlocklist dedupes case-insensitively", () => {
+ const out = normalizeBlocklist(["A.com", "a.com", " A.COM "]);
+
+ assert.deepEqual(out, ["a.com"]);
+});
+
+test("normalizeBlocklist ignores non-strings and empty entries", () => {
+ const out = normalizeBlocklist(["valid.com", null, 42, "", " "]);
+
+ assert.deepEqual(out, ["valid.com"]);
+});
+
+test("normalizeBlocklist returns an empty array for non-array input", () => {
+ assert.deepEqual(normalizeBlocklist(null), []);
+ assert.deepEqual(normalizeBlocklist(undefined), []);
+ assert.deepEqual(normalizeBlocklist("not-an-array"), []);
+});
+
+test("mergeBlocklists concatenates defaults and user without duplicates", () => {
+ const merged = mergeBlocklists(["a.com", "b.com"], ["b.com", "c.com"]);
+
+ assert.deepEqual(merged.sort(), ["a.com", "b.com", "c.com"].sort());
+});
+
+test("mergeBlocklists preserves defaults when user input is empty or invalid", () => {
+ assert.deepEqual(mergeBlocklists(["a.com"], null), ["a.com"]);
+ assert.deepEqual(mergeBlocklists(["a.com"], []), ["a.com"]);
+ assert.deepEqual(mergeBlocklists(["a.com"], "garbage"), ["a.com"]);
+});
+
+test("isHostBlocked returns true when any blocklist entry is a substring of the host", () => {
+ const blocklist = ["analytics", "doubleclick.net"];
+
+ assert.equal(isHostBlocked("www.google-analytics.com", blocklist), true);
+ assert.equal(isHostBlocked("ad.doubleclick.net", blocklist), true);
+});
+
+test("isHostBlocked returns false for unrelated hosts", () => {
+ const blocklist = ["doubleclick.net"];
+
+ assert.equal(isHostBlocked("example.com", blocklist), false);
+});
+
+test("isHostBlocked returns false for empty or invalid host input", () => {
+ assert.equal(isHostBlocked("", ["anything"]), false);
+ assert.equal(isHostBlocked(null, ["anything"]), false);
+ assert.equal(isHostBlocked(undefined, ["anything"]), false);
+});
+
+test("isUrlHostBlocked parses host and delegates to isHostBlocked", () => {
+ const blocklist = ["sentry.io"];
+
+ assert.equal(isUrlHostBlocked("https://o123.ingest.sentry.io/foo", blocklist), true);
+ assert.equal(isUrlHostBlocked("https://example.com/foo", blocklist), false);
+});
+
+test("isUrlHostBlocked returns false for malformed URLs", () => {
+ assert.equal(isUrlHostBlocked("not a url", DEFAULT_BLOCKED_HOSTS), false);
+ assert.equal(isUrlHostBlocked("", DEFAULT_BLOCKED_HOSTS), false);
+});
+
+test("user-supplied entry can extend the default blocklist", () => {
+ const merged = mergeBlocklists(DEFAULT_BLOCKED_HOSTS, ["my-tracker.example"]);
+
+ assert.ok(merged.includes("my-tracker.example"));
+ assert.equal(isHostBlocked("cdn.my-tracker.example", merged), true);
+});
diff --git a/browser-extension/chrome/tests/cookie-summary.test.mjs b/browser-extension/chrome/tests/cookie-summary.test.mjs
new file mode 100644
index 00000000..0957d1ea
--- /dev/null
+++ b/browser-extension/chrome/tests/cookie-summary.test.mjs
@@ -0,0 +1,101 @@
+import test from "node:test";
+import assert from "node:assert/strict";
+
+import { formatCookieSummary, summarizeCookies } from "../src/cookie-summary.js";
+
+test("summarizeCookies returns null for empty or non-array input", () => {
+ assert.equal(summarizeCookies([]), null);
+ assert.equal(summarizeCookies(null), null);
+ assert.equal(summarizeCookies(undefined), null);
+ assert.equal(summarizeCookies("cookies"), null);
+});
+
+test("summarizeCookies counts cookies and strips leading dot from domain", () => {
+ const summary = summarizeCookies([
+ { domain: ".example.com", name: "a" },
+ { domain: ".example.com", name: "b" },
+ ]);
+ assert.deepEqual(summary, {
+ count: 2,
+ primaryDomain: "example.com",
+ domainCount: 1,
+ });
+});
+
+test("summarizeCookies lowercases mixed-case domains", () => {
+ const summary = summarizeCookies([
+ { domain: ".Example.COM", name: "a" },
+ { domain: "example.com", name: "b" },
+ ]);
+ assert.equal(summary.primaryDomain, "example.com");
+ assert.equal(summary.domainCount, 1);
+});
+
+test("summarizeCookies picks the domain with the most cookies as primary", () => {
+ const summary = summarizeCookies([
+ { domain: ".cdn.example.com", name: "a" },
+ { domain: ".example.com", name: "b" },
+ { domain: ".example.com", name: "c" },
+ { domain: ".example.com", name: "d" },
+ ]);
+ assert.equal(summary.primaryDomain, "example.com");
+ assert.equal(summary.domainCount, 2);
+ assert.equal(summary.count, 4);
+});
+
+test("summarizeCookies breaks ties deterministically by domain", () => {
+ const summary = summarizeCookies([
+ { domain: "b.example.com", name: "a" },
+ { domain: "a.example.com", name: "b" },
+ ]);
+ assert.equal(summary.primaryDomain, "a.example.com");
+});
+
+test("summarizeCookies ignores entries without a domain", () => {
+ const summary = summarizeCookies([
+ { name: "a" },
+ { domain: "", name: "b" },
+ { domain: "example.com", name: "c" },
+ ]);
+ assert.equal(summary.count, 3);
+ assert.equal(summary.primaryDomain, "example.com");
+ assert.equal(summary.domainCount, 1);
+});
+
+test("summarizeCookies returns null when no domain can be extracted", () => {
+ assert.equal(summarizeCookies([{ name: "a" }, { domain: "" }]), null);
+});
+
+test("formatCookieSummary shows single-domain message", () => {
+ assert.equal(
+ formatCookieSummary({ count: 12, primaryDomain: "instagram.com", domainCount: 1 }),
+ "12 cookies from instagram.com sent",
+ );
+});
+
+test("formatCookieSummary shows multi-domain message with correct pluralization", () => {
+ assert.equal(
+ formatCookieSummary({ count: 20, primaryDomain: "instagram.com", domainCount: 2 }),
+ "20 cookies from instagram.com and 1 other domain sent",
+ );
+ assert.equal(
+ formatCookieSummary({ count: 30, primaryDomain: "instagram.com", domainCount: 4 }),
+ "30 cookies from instagram.com and 3 other domains sent",
+ );
+});
+
+test("formatCookieSummary returns empty for null/zero/invalid input", () => {
+ assert.equal(formatCookieSummary(null), "");
+ assert.equal(formatCookieSummary(undefined), "");
+ assert.equal(formatCookieSummary({ count: 0, primaryDomain: "x.com", domainCount: 1 }), "");
+});
+
+test("summarizeCookies does not leak cookie values or names", () => {
+ const summary = summarizeCookies([
+ { domain: ".example.com", name: "SESSION_SECRET", value: "s3cret-payload" },
+ ]);
+ assert.ok(!("name" in summary));
+ assert.ok(!("value" in summary));
+ assert.ok(!JSON.stringify(summary).includes("SESSION_SECRET"));
+ assert.ok(!JSON.stringify(summary).includes("s3cret-payload"));
+});
diff --git a/browser-extension/chrome/tests/cookies.test.mjs b/browser-extension/chrome/tests/cookies.test.mjs
index 25200a24..5a476c8f 100644
--- a/browser-extension/chrome/tests/cookies.test.mjs
+++ b/browser-extension/chrome/tests/cookies.test.mjs
@@ -1,7 +1,15 @@
import test from "node:test";
import assert from "node:assert/strict";
+import { readFile } from "node:fs/promises";
-import { extractCookiesForPlatform } from "../src/cookies.js";
+import {
+ COOKIE_DOMAINS_RESOURCE_PATH,
+ DEFAULT_PLATFORM_COOKIE_DOMAINS,
+ extractCookiesForPlatform,
+ getPlatformCookieDomainsCacheSource,
+ loadPlatformCookieDomains,
+ resetPlatformCookieDomainsCacheForTesting,
+} from "../src/cookies.js";
function mockGetAllCookies(cookieStore) {
return async ({ domain }) => cookieStore[domain] ?? [];
@@ -129,3 +137,102 @@ test("uses default fallback when chrome.cookies is unavailable", async () => {
const cookies = await extractCookiesForPlatform("youtube");
assert.equal(cookies, null);
});
+
+test("loadPlatformCookieDomains returns the default map when no chrome resource is available", async () => {
+ resetPlatformCookieDomainsCacheForTesting();
+ const domains = await loadPlatformCookieDomains();
+
+ assert.deepEqual(domains, DEFAULT_PLATFORM_COOKIE_DOMAINS);
+ assert.equal(getPlatformCookieDomainsCacheSource(), "default");
+});
+
+test("loadPlatformCookieDomains is cached after the first call", async () => {
+ resetPlatformCookieDomainsCacheForTesting();
+ const first = await loadPlatformCookieDomains();
+ const second = await loadPlatformCookieDomains();
+
+ assert.equal(first, second);
+});
+
+test("default domains include all currently detectable platforms", async () => {
+ const required = [
+ "youtube",
+ "instagram",
+ "tiktok",
+ "twitter",
+ "reddit",
+ "twitch",
+ "vimeo",
+ "bilibili",
+ "pinterest",
+ "hotmart",
+ "udemy",
+ "bluesky",
+ "telegram",
+ ];
+ for (const key of required) {
+ assert.ok(
+ Array.isArray(DEFAULT_PLATFORM_COOKIE_DOMAINS[key]) &&
+ DEFAULT_PLATFORM_COOKIE_DOMAINS[key].length > 0,
+ `DEFAULT_PLATFORM_COOKIE_DOMAINS missing platform ${key}`,
+ );
+ }
+});
+
+test("shipped cookies-domains.json matches DEFAULT_PLATFORM_COOKIE_DOMAINS", async () => {
+ const jsonUrl = new URL(`../${COOKIE_DOMAINS_RESOURCE_PATH}`, import.meta.url);
+ const json = JSON.parse(await readFile(jsonUrl, "utf8"));
+
+ assert.deepEqual(
+ json,
+ Object.fromEntries(
+ Object.entries(DEFAULT_PLATFORM_COOKIE_DOMAINS).map(([k, v]) => [k, [...v]]),
+ ),
+ );
+});
+
+test("extractCookiesForPlatform accepts a domainsOverride for injection testing", async () => {
+ const cookies = await extractCookiesForPlatform(
+ "mynewplatform",
+ mockGetAllCookies({
+ ".mynewplatform.com": [
+ { domain: ".mynewplatform.com", httpOnly: false, path: "/", secure: true, expirationDate: 1, name: "n", value: "v" },
+ ],
+ }),
+ { mynewplatform: [".mynewplatform.com"] },
+ );
+
+ assert.ok(cookies);
+ assert.equal(cookies.length, 1);
+ assert.equal(cookies[0].domain, ".mynewplatform.com");
+});
+
+test("bluesky platform is now data-driven and resolves to bsky domains", async () => {
+ const cookies = await extractCookiesForPlatform(
+ "bluesky",
+ mockGetAllCookies({
+ ".bsky.app": [
+ { domain: ".bsky.app", httpOnly: true, path: "/", secure: true, expirationDate: 42, name: "auth", value: "x" },
+ ],
+ }),
+ );
+
+ assert.ok(cookies);
+ assert.equal(cookies.length, 1);
+ assert.equal(cookies[0].domain, ".bsky.app");
+});
+
+test("telegram platform is now data-driven and resolves to telegram.org", async () => {
+ const cookies = await extractCookiesForPlatform(
+ "telegram",
+ mockGetAllCookies({
+ ".telegram.org": [
+ { domain: ".telegram.org", httpOnly: false, path: "/", secure: true, expirationDate: 0, name: "stel", value: "y" },
+ ],
+ }),
+ );
+
+ assert.ok(cookies);
+ assert.equal(cookies.length, 1);
+ assert.equal(cookies[0].domain, ".telegram.org");
+});
diff --git a/browser-extension/chrome/tests/hls-grouping.test.mjs b/browser-extension/chrome/tests/hls-grouping.test.mjs
new file mode 100644
index 00000000..cf2c66c3
--- /dev/null
+++ b/browser-extension/chrome/tests/hls-grouping.test.mjs
@@ -0,0 +1,71 @@
+import test from "node:test";
+import assert from "node:assert/strict";
+
+import { getHlsGroupKey, getHlsVariantToken } from "../src/hls-grouping.js";
+
+test("variant token collapses master-like names to 'master'", () => {
+ assert.equal(getHlsVariantToken("master.m3u8"), "master");
+ assert.equal(getHlsVariantToken("playlist.m3u8"), "master");
+ assert.equal(getHlsVariantToken("index.m3u8"), "master");
+ assert.equal(getHlsVariantToken("main.m3u8"), "master");
+ assert.equal(getHlsVariantToken("manifest.m3u8"), "master");
+});
+
+test("variant token collapses pure resolution names to 'master'", () => {
+ assert.equal(getHlsVariantToken("1080.m3u8"), "master");
+ assert.equal(getHlsVariantToken("1080p.m3u8"), "master");
+ assert.equal(getHlsVariantToken("720p.m3u8"), "master");
+ assert.equal(getHlsVariantToken("480.m3u8"), "master");
+});
+
+test("variant token collapses quality labels to 'master'", () => {
+ assert.equal(getHlsVariantToken("high.m3u8"), "master");
+ assert.equal(getHlsVariantToken("hd.m3u8"), "master");
+ assert.equal(getHlsVariantToken("auto.m3u8"), "master");
+});
+
+test("variant token preserves distinct video identifiers", () => {
+ assert.equal(getHlsVariantToken("moviea_master.m3u8"), "moviea_master");
+ assert.equal(getHlsVariantToken("movieb_master.m3u8"), "movieb_master");
+ assert.equal(getHlsVariantToken("session-abc123.m3u8"), "session-abc123");
+});
+
+test("variant token is case-insensitive", () => {
+ assert.equal(getHlsVariantToken("MASTER.M3U8"), "master");
+ assert.equal(getHlsVariantToken("Playlist.M3U8"), "master");
+});
+
+test("variant token strips query string before matching", () => {
+ assert.equal(getHlsVariantToken("master.m3u8?token=abc"), "master");
+ assert.equal(getHlsVariantToken("moviea.m3u8?sig=xyz"), "moviea");
+});
+
+test("group key keeps distinct videos in the same directory separate", () => {
+ const keyA = getHlsGroupKey("https://cdn.example.com/videos/moviea_master.m3u8");
+ const keyB = getHlsGroupKey("https://cdn.example.com/videos/movieb_master.m3u8");
+ assert.notEqual(keyA, keyB);
+});
+
+test("group key groups master with its numeric variants in the same directory", () => {
+ const master = getHlsGroupKey("https://cdn.example.com/video1/master.m3u8");
+ const v1080 = getHlsGroupKey("https://cdn.example.com/video1/1080p.m3u8");
+ const v720 = getHlsGroupKey("https://cdn.example.com/video1/720.m3u8");
+ assert.equal(master, v1080);
+ assert.equal(master, v720);
+});
+
+test("group key differentiates different directories", () => {
+ const keyA = getHlsGroupKey("https://cdn.example.com/videoA/master.m3u8");
+ const keyB = getHlsGroupKey("https://cdn.example.com/videoB/master.m3u8");
+ assert.notEqual(keyA, keyB);
+});
+
+test("group key differentiates different origins", () => {
+ const keyA = getHlsGroupKey("https://cdn1.example.com/videos/master.m3u8");
+ const keyB = getHlsGroupKey("https://cdn2.example.com/videos/master.m3u8");
+ assert.notEqual(keyA, keyB);
+});
+
+test("group key falls back to raw url for invalid input", () => {
+ assert.equal(getHlsGroupKey("not-a-url"), "not-a-url");
+});
diff --git a/browser-extension/chrome/tests/manifest.test.mjs b/browser-extension/chrome/tests/manifest.test.mjs
index 4af429cd..f329805c 100644
--- a/browser-extension/chrome/tests/manifest.test.mjs
+++ b/browser-extension/chrome/tests/manifest.test.mjs
@@ -38,8 +38,56 @@ test("declares storage permission for sniffer toggle", async () => {
assert.ok(manifest.permissions.includes("storage"));
});
-test("declares wildcard host_permissions for media detection", async () => {
+test("declares platform-scoped host_permissions instead of a wildcard", async () => {
const manifest = await readManifest();
- assert.ok(manifest.host_permissions.includes("*://*/*"));
+ assert.ok(Array.isArray(manifest.host_permissions), "host_permissions must be an array");
+ assert.ok(
+ !manifest.host_permissions.includes("*://*/*"),
+ "host_permissions must not ship a wildcard by default",
+ );
+
+ const requiredPatterns = [
+ "*://*.hotmart.com/*",
+ "*://*.youtube.com/*",
+ "*://youtu.be/*",
+ "*://*.instagram.com/*",
+ "*://*.tiktok.com/*",
+ "*://*.twitter.com/*",
+ "*://*.x.com/*",
+ "*://*.reddit.com/*",
+ "*://*.twitch.tv/*",
+ "*://*.pinterest.com/*",
+ "*://bsky.app/*",
+ "*://t.me/*",
+ "*://*.vimeo.com/*",
+ "*://*.udemy.com/*",
+ "*://*.bilibili.com/*",
+ ];
+ for (const pattern of requiredPatterns) {
+ assert.ok(
+ manifest.host_permissions.includes(pattern),
+ `host_permissions missing required pattern ${pattern}`,
+ );
+ }
+});
+
+test("declares wildcard host access in optional_host_permissions for media sniffer", async () => {
+ const manifest = await readManifest();
+
+ assert.ok(
+ Array.isArray(manifest.optional_host_permissions),
+ "optional_host_permissions must be an array",
+ );
+ assert.ok(manifest.optional_host_permissions.includes("*://*/*"));
+});
+
+test("declares the send-to-omniget command with Alt+O default shortcut", async () => {
+ const manifest = await readManifest();
+
+ assert.ok(manifest.commands, "manifest.commands block missing");
+ const command = manifest.commands["send-to-omniget"];
+ assert.ok(command, "send-to-omniget command missing");
+ assert.equal(command.suggested_key?.default, "Alt+O");
+ assert.ok(typeof command.description === "string" && command.description.length > 0);
});
diff --git a/browser-extension/chrome/tests/sniffer-filters.test.mjs b/browser-extension/chrome/tests/sniffer-filters.test.mjs
new file mode 100644
index 00000000..4b61cf99
--- /dev/null
+++ b/browser-extension/chrome/tests/sniffer-filters.test.mjs
@@ -0,0 +1,56 @@
+import test from "node:test";
+import assert from "node:assert/strict";
+
+import {
+ DASH_MIN_CONTENT_LENGTH,
+ MIN_CONTENT_LENGTH,
+ isDashManifest,
+ isHlsManifest,
+ shouldDropBySize,
+} from "../src/sniffer-filters.js";
+
+test("isHlsManifest matches by URL extension and content-type", () => {
+ assert.equal(isHlsManifest("https://cdn.example.com/master.m3u8", ""), true);
+ assert.equal(isHlsManifest("https://cdn.example.com/MASTER.M3U8?token=x", ""), true);
+ assert.equal(isHlsManifest("https://cdn.example.com/play", "application/x-mpegURL"), true);
+ assert.equal(isHlsManifest("https://cdn.example.com/play", "application/vnd.apple.mpegurl"), true);
+ assert.equal(isHlsManifest("https://cdn.example.com/play.mp4", "video/mp4"), false);
+});
+
+test("isDashManifest matches by URL extension and content-type", () => {
+ assert.equal(isDashManifest("https://cdn.example.com/manifest.mpd", ""), true);
+ assert.equal(isDashManifest("https://cdn.example.com/manifest.MPD?sig=y", ""), true);
+ assert.equal(isDashManifest("https://cdn.example.com/play", "application/dash+xml"), true);
+ assert.equal(isDashManifest("https://cdn.example.com/play.mp4", "video/mp4"), false);
+});
+
+test("shouldDropBySize keeps responses when content-length is unknown", () => {
+ assert.equal(shouldDropBySize("https://cdn.example.com/file.mp4", "video/mp4", 0), false);
+ assert.equal(shouldDropBySize("https://cdn.example.com/file.mp4", "video/mp4", null), false);
+ assert.equal(shouldDropBySize("https://cdn.example.com/file.mp4", "video/mp4", undefined), false);
+});
+
+test("shouldDropBySize drops non-manifest media under 50 KB", () => {
+ assert.equal(shouldDropBySize("https://cdn.example.com/tiny.mp4", "video/mp4", 1024), true);
+ assert.equal(shouldDropBySize("https://cdn.example.com/big.mp4", "video/mp4", 200_000), false);
+});
+
+test("shouldDropBySize never drops HLS manifests by size", () => {
+ assert.equal(shouldDropBySize("https://cdn.example.com/master.m3u8", "", 512), false);
+ assert.equal(shouldDropBySize("https://cdn.example.com/small.m3u8", "application/x-mpegURL", 100), false);
+ assert.equal(shouldDropBySize("https://cdn.example.com/big.m3u8", "application/x-mpegURL", 5_000_000), false);
+});
+
+test("shouldDropBySize drops DASH manifests below the DASH floor", () => {
+ assert.equal(shouldDropBySize("https://cdn.example.com/error.mpd", "application/dash+xml", 128), true);
+ assert.equal(shouldDropBySize("https://cdn.example.com/error.mpd", "application/dash+xml", DASH_MIN_CONTENT_LENGTH - 1), true);
+});
+
+test("shouldDropBySize keeps DASH manifests at or above the DASH floor", () => {
+ assert.equal(shouldDropBySize("https://cdn.example.com/live.mpd", "application/dash+xml", DASH_MIN_CONTENT_LENGTH), false);
+ assert.equal(shouldDropBySize("https://cdn.example.com/vod.mpd", "application/dash+xml", 30_000), false);
+});
+
+test("DASH floor is below the generic floor to allow legitimate small MPDs", () => {
+ assert.ok(DASH_MIN_CONTENT_LENGTH < MIN_CONTENT_LENGTH);
+});
diff --git a/browser-extension/chrome/tests/sniffer-storage.test.mjs b/browser-extension/chrome/tests/sniffer-storage.test.mjs
new file mode 100644
index 00000000..2745a485
--- /dev/null
+++ b/browser-extension/chrome/tests/sniffer-storage.test.mjs
@@ -0,0 +1,111 @@
+import test from "node:test";
+import assert from "node:assert/strict";
+
+import {
+ DEFAULT_PAGE_TTL_MS,
+ PAGE_KEY_STORAGE_PREFIX,
+ classifyStoredPages,
+ isExpired,
+ normalizePageKey,
+ pageKeyFromStorageKey,
+ storageKeyForPage,
+} from "../src/sniffer-storage.js";
+
+test("normalizePageKey strips query and hash but keeps origin+path", () => {
+ assert.equal(
+ normalizePageKey("https://www.example.com/watch?v=123&list=abc#top"),
+ "https://www.example.com/watch",
+ );
+});
+
+test("normalizePageKey lowercases the host", () => {
+ assert.equal(
+ normalizePageKey("https://WWW.Example.com/Video/ID-42"),
+ "https://www.example.com/Video/ID-42",
+ );
+});
+
+test("normalizePageKey preserves path case (case-sensitive paths)", () => {
+ assert.equal(
+ normalizePageKey("https://example.com/User/Profile"),
+ "https://example.com/User/Profile",
+ );
+});
+
+test("normalizePageKey returns null for non-http(s) URLs", () => {
+ assert.equal(normalizePageKey("chrome://extensions"), null);
+ assert.equal(normalizePageKey("file:///tmp/a.html"), null);
+ assert.equal(normalizePageKey("javascript:void(0)"), null);
+ assert.equal(normalizePageKey(""), null);
+ assert.equal(normalizePageKey(null), null);
+ assert.equal(normalizePageKey("not-a-url"), null);
+});
+
+test("normalizePageKey defaults empty path to '/'", () => {
+ assert.equal(normalizePageKey("https://example.com"), "https://example.com/");
+});
+
+test("storageKeyForPage / pageKeyFromStorageKey round-trip", () => {
+ const pageKey = "https://example.com/watch";
+ const storageKey = storageKeyForPage(pageKey);
+ assert.ok(storageKey.startsWith(PAGE_KEY_STORAGE_PREFIX));
+ assert.equal(pageKeyFromStorageKey(storageKey), pageKey);
+});
+
+test("pageKeyFromStorageKey ignores foreign keys", () => {
+ assert.equal(pageKeyFromStorageKey("sniffer_enabled"), null);
+ assert.equal(pageKeyFromStorageKey("media_42"), null);
+ assert.equal(pageKeyFromStorageKey(null), null);
+ assert.equal(pageKeyFromStorageKey(42), null);
+});
+
+test("isExpired returns true for missing or malformed timestamps", () => {
+ assert.equal(isExpired(undefined, 1000), true);
+ assert.equal(isExpired(NaN, 1000), true);
+ assert.equal(isExpired("abc", 1000), true);
+});
+
+test("isExpired respects TTL window", () => {
+ const now = 1_000_000;
+ assert.equal(isExpired(now - 1000, now, 10_000), false);
+ assert.equal(isExpired(now - 20_000, now, 10_000), true);
+ assert.equal(isExpired(now, now, 10_000), false);
+});
+
+test("isExpired treats future timestamps as not expired", () => {
+ const now = 1_000_000;
+ assert.equal(isExpired(now + 5000, now, 10_000), false);
+});
+
+test("classifyStoredPages separates valid from stale and ignores unrelated keys", () => {
+ const now = 5_000_000;
+ const storage = {
+ "sniffer_enabled": true,
+ [storageKeyForPage("https://a.example.com/x")]: {
+ media: [["u", { title: "t" }]],
+ savedAt: now - 1000,
+ },
+ [storageKeyForPage("https://b.example.com/y")]: {
+ media: [],
+ savedAt: now - DEFAULT_PAGE_TTL_MS - 1,
+ },
+ [storageKeyForPage("https://c.example.com/z")]: {
+ savedAt: now - 1000,
+ },
+ [storageKeyForPage("https://d.example.com/w")]: null,
+ };
+ const { valid, stale } = classifyStoredPages(storage, now);
+ assert.equal(valid.length, 1);
+ assert.equal(valid[0].pageKey, "https://a.example.com/x");
+ assert.equal(valid[0].media.length, 1);
+ assert.ok(stale.includes(storageKeyForPage("https://b.example.com/y")));
+ assert.ok(stale.includes(storageKeyForPage("https://c.example.com/z")));
+ assert.ok(stale.includes(storageKeyForPage("https://d.example.com/w")));
+ assert.equal(stale.length, 3);
+});
+
+test("classifyStoredPages handles null or non-object input gracefully", () => {
+ const { valid, stale } = classifyStoredPages(null, 1000);
+ assert.deepEqual(valid, []);
+ assert.deepEqual(stale, []);
+});
diff --git a/browser-extension/chrome/tests/sniffer-toggle.test.mjs b/browser-extension/chrome/tests/sniffer-toggle.test.mjs
new file mode 100644
index 00000000..4069c190
--- /dev/null
+++ b/browser-extension/chrome/tests/sniffer-toggle.test.mjs
@@ -0,0 +1,116 @@
+import test from "node:test";
+import assert from "node:assert/strict";
+
+function makeChromeStub({ grant = true, storage = {}, hasContains = true, hasRequest = true } = {}) {
+ const backing = { ...storage };
+ const calls = { contains: 0, request: 0 };
+ const chrome = {
+ permissions: {},
+ storage: {
+ local: {
+ get: async (key) => {
+ if (typeof key === "string") {
+ return key in backing ? { [key]: backing[key] } : {};
+ }
+ return { ...backing };
+ },
+ set: async (obj) => {
+ Object.assign(backing, obj);
+ },
+ },
+ },
+ __backing: backing,
+ __calls: calls,
+ };
+ if (hasContains) {
+ chrome.permissions.contains = async () => {
+ calls.contains += 1;
+ return grant;
+ };
+ }
+ if (hasRequest) {
+ chrome.permissions.request = async () => {
+ calls.request += 1;
+ return grant;
+ };
+ }
+ return chrome;
+}
+
+async function loadModuleFresh() {
+ const url = new URL("../src/sniffer-toggle.js", import.meta.url);
+ url.searchParams.set("_t", String(Math.random()));
+ return await import(url.href);
+}
+
+test("enabling the sniffer requests wildcard permission and succeeds when granted", async () => {
+ globalThis.chrome = makeChromeStub({ grant: true });
+ const mod = await loadModuleFresh();
+
+ const result = await mod.setSnifferEnabled(true);
+
+ assert.deepEqual(result, { ok: true });
+ assert.equal(globalThis.chrome.__calls.request, 1);
+ assert.equal(globalThis.chrome.__backing.omniget_sniffer_enabled, true);
+ assert.equal(mod.isSnifferEnabled(), true);
+});
+
+test("enabling the sniffer fails closed and does not persist when permission is denied", async () => {
+ globalThis.chrome = makeChromeStub({ grant: false });
+ const mod = await loadModuleFresh();
+
+ const result = await mod.setSnifferEnabled(true);
+
+ assert.equal(result.ok, false);
+ assert.equal(result.reason, "permission_denied");
+ assert.equal(globalThis.chrome.__backing.omniget_sniffer_enabled, false);
+ assert.equal(mod.isSnifferEnabled(), false);
+});
+
+test("disabling the sniffer never requests permission", async () => {
+ globalThis.chrome = makeChromeStub({ grant: true });
+ const mod = await loadModuleFresh();
+
+ const result = await mod.setSnifferEnabled(false);
+
+ assert.deepEqual(result, { ok: true });
+ assert.equal(globalThis.chrome.__calls.request, 0);
+ assert.equal(globalThis.chrome.__backing.omniget_sniffer_enabled, false);
+ assert.equal(mod.isSnifferEnabled(), false);
+});
+
+test("hasWildcardHostPermission returns true when chrome.permissions is unavailable", async () => {
+ globalThis.chrome = { storage: { local: { get: async () => ({}), set: async () => {} } } };
+ const mod = await loadModuleFresh();
+
+ const has = await mod.hasWildcardHostPermission();
+
+ assert.equal(has, true);
+});
+
+test("requestWildcardHostPermission returns true when chrome.permissions.request is unavailable", async () => {
+ globalThis.chrome = makeChromeStub({ hasRequest: false });
+ const mod = await loadModuleFresh();
+
+ const granted = await mod.requestWildcardHostPermission();
+
+ assert.equal(granted, true);
+});
+
+test("loadSnifferState defaults to enabled when no prior setting", async () => {
+ globalThis.chrome = makeChromeStub({ storage: {} });
+ const mod = await loadModuleFresh();
+
+ const enabled = await mod.loadSnifferState();
+
+ assert.equal(enabled, true);
+});
+
+test("loadSnifferState honours a previously-disabled flag", async () => {
+ globalThis.chrome = makeChromeStub({ storage: { omniget_sniffer_enabled: false } });
+ const mod = await loadModuleFresh();
+
+ const enabled = await mod.loadSnifferState();
+
+ assert.equal(enabled, false);
+});
diff --git a/browser-extension/firefox/manifest.json b/browser-extension/firefox/manifest.json
index dada3b80..4226c311 100644
--- a/browser-extension/firefox/manifest.json
+++ b/browser-extension/firefox/manifest.json
@@ -19,6 +19,62 @@
"menus"
],
"host_permissions": [
+ "*://*.hotmart.com/*",
+ "*://*.youtube.com/*",
+ "*://*.youtube-nocookie.com/*",
+ "*://youtu.be/*",
+ "*://*.googlevideo.com/*",
+ "*://*.ytimg.com/*",
+ "*://*.instagram.com/*",
+ "*://*.ddinstagram.com/*",
+ "*://*.cdninstagram.com/*",
+ "*://*.fbcdn.net/*",
+ "*://*.tiktok.com/*",
+ "*://*.tiktokcdn.com/*",
+ "*://*.tiktokcdn-us.com/*",
+ "*://*.twitter.com/*",
+ "*://*.x.com/*",
+ "*://*.vxtwitter.com/*",
+ "*://*.fixvx.com/*",
+ "*://*.twimg.com/*",
+ "*://*.reddit.com/*",
+ "*://v.redd.it/*",
+ "*://redd.it/*",
+ "*://*.redditmedia.com/*",
+ "*://*.twitch.tv/*",
+ "*://*.jtvnw.net/*",
+ "*://*.ttvnw.net/*",
+ "*://pin.it/*",
+ "*://*.pinterest.com/*",
+ "*://*.pinterest.ca/*",
+ "*://*.pinterest.co.uk/*",
+ "*://*.pinterest.com.au/*",
+ "*://*.pinterest.de/*",
+ "*://*.pinterest.fr/*",
+ "*://*.pinterest.jp/*",
+ "*://*.pinterest.es/*",
+ "*://*.pinterest.it/*",
+ "*://*.pinterest.mx/*",
+ "*://*.pinterest.nz/*",
+ "*://*.pinterest.ph/*",
+ "*://*.pinterest.pt/*",
+ "*://*.pinterest.se/*",
+ "*://*.pinimg.com/*",
+ "*://bsky.app/*",
+ "*://*.bsky.app/*",
+ "*://*.bsky.social/*",
+ "*://t.me/*",
+ "*://*.telegram.me/*",
+ "*://*.telegram.org/*",
+ "*://*.vimeo.com/*",
+ "*://*.vimeocdn.com/*",
+ "*://*.udemy.com/*",
+ "*://*.udemycdn.com/*",
+ "*://*.bilibili.com/*",
+ "*://*.bilivideo.com/*",
+ "*://b23.tv/*"
+ ],
+ "optional_host_permissions": [
"*://*/*"
],
"background": {
@@ -41,5 +97,13 @@
"32": "icons/active-32.png",
"48": "icons/active-48.png",
"128": "icons/active-128.png"
+ },
+ "commands": {
+ "send-to-omniget": {
+ "suggested_key": {
+ "default": "Alt+O"
+ },
+ "description": "Send current page to OmniGet"
+ }
}
}
diff --git a/browser-extension/firefox/popup/popup.css b/browser-extension/firefox/popup/popup.css
index c0a8403f..bd2c4c3c 100644
--- a/browser-extension/firefox/popup/popup.css
+++ b/browser-extension/firefox/popup/popup.css
@@ -37,11 +37,29 @@ body {
}
.header-left { display: flex; align-items: center; gap: 8px; }
-.header-toggles { display: flex; align-items: center; gap: 10px; }
+.header-toggles { display: flex; align-items: center; gap: 14px; }
.logo { width: 16px; height: 16px; }
.title { font-weight: 600; font-size: 14px; }
-.toggle { position: relative; display: inline-block; width: 36px; height: 20px; cursor: pointer; }
+.toggle-group {
+ display: inline-flex;
+ align-items: center;
+ gap: 6px;
+ cursor: pointer;
+ color: var(--text-secondary);
+ transition: color 0.2s ease;
+}
+
+.toggle-group:hover { color: var(--text-primary); }
+.toggle-group:has(input:checked) { color: var(--text-primary); }
+
+.toggle-icon {
+ width: 14px;
+ height: 14px;
+ flex-shrink: 0;
+}
+
+.toggle { position: relative; display: inline-block; width: 36px; height: 20px; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-slider {
diff --git a/browser-extension/firefox/popup/popup.html b/browser-extension/firefox/popup/popup.html
index a283c1a7..ea56befc 100644
--- a/browser-extension/firefox/popup/popup.html
+++ b/browser-extension/firefox/popup/popup.html
@@ -13,13 +13,28 @@
<span class="title">OmniGet</span>
</div>
<div class="header-toggles">
- <label class="toggle" title="Open app when downloading">
- <input type="checkbox" id="open-app-toggle" role="switch" aria-label="Open app when downloading">
- <span class="toggle-slider"></span>
+ <label class="toggle-group" title="Open app when downloading">
+ <svg class="toggle-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
+ <path d="M15 3h6v6"/>
+ <path d="M10 14 21 3"/>
+ <path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/>
+ </svg>
+ <span class="toggle">
+ <input type="checkbox" id="open-app-toggle" role="switch" aria-label="Open app when downloading">
+ <span class="toggle-slider"></span>
+ </span>
</label>
- <label class="toggle" title="Media detection">
- <input type="checkbox" id="sniffer-toggle" role="switch" aria-label="Media detection">
- <span class="toggle-slider"></span>
+ <label class="toggle-group" title="Media detection">
+ <svg class="toggle-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
+ <path d="M5 12.55a11 11 0 0 1 14.08 0"/>
+ <path d="M1.42 9a16 16 0 0 1 21.16 0"/>
+ <path d="M8.53 16.11a6 6 0 0 1 6.95 0"/>
+ <line x1="12" y1="20" x2="12.01" y2="20"/>
+ </svg>
+ <span class="toggle">
+ <input type="checkbox" id="sniffer-toggle" role="switch" aria-label="Media detection">
+ <span class="toggle-slider"></span>
+ </span>
</label>
</div>
</header>