Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.
Rust downloadmanagerguihacktoberfesthomebrewlightweightlinuxlinux-distributionlocal-firstmacosmacos-packagemedia-toolboxopen-sourcerustsveltetauritrendingtrending-repositorieswindowswindows-desktopytdlp
Fix Chrome extension production readiness issues
InstaZDLLf9b733c47ed4
diff --git a/browser-extension/chrome/README.md b/browser-extension/chrome/README.mdindex ea4afbbb..2762b33a 100644--- a/browser-extension/chrome/README.md+++ b/browser-extension/chrome/README.md@@ -16,6 +16,14 @@ The unpacked extension keeps a stable ID through the committed manifest key:`dkjelkhaaakffpghdfalobccaaipajip`+## Chrome Web Store packaging++The committed `manifest.json` intentionally keeps its `key` so local unpacked installs keep the same development ID.++Before submitting a package to the Chrome Web Store, remove the `key` field from the submitted copy of `manifest.json`. The Chrome Web Store will assign its own extension ID.++Once the store ID is known, add it to the Chrome native host allowlist in [`src-tauri/src/native_host.rs`](/E:/Workspace/omniget/src-tauri/src/native_host.rs) so the published extension can talk to OmniGet alongside the unpacked development build.+## What it does- Colors the toolbar icon on supported media pages only.@@ -26,5 +34,5 @@ The unpacked extension keeps a stable ID through the committed manifest key:## Quick test```powershell-node --test browser-extension/chrome/tests/detect.test.mjs browser-extension/chrome/tests/action-title.test.mjs+node --test browser-extension/chrome/tests/action-title.test.mjs browser-extension/chrome/tests/action-click.test.mjs browser-extension/chrome/tests/action-feedback.test.mjs browser-extension/chrome/tests/detect.test.mjs browser-extension/chrome/tests/error-content.test.mjs browser-extension/chrome/tests/manifest.test.mjs```diff --git a/browser-extension/chrome/_locales/el/messages.json b/browser-extension/chrome/_locales/el/messages.jsonindex 4a499585..744f5b6a 100644--- a/browser-extension/chrome/_locales/el/messages.json+++ b/browser-extension/chrome/_locales/el/messages.json@@ -4,5 +4,44 @@},"action_title_unsupported": {"message": "Δεν εντοπίστηκαν υποστηριζόμενα πολυμέσα σε αυτήν τη σελίδα"+ },+ "error_page_document_title": {+ "message": "Επέκταση OmniGet"+ },+ "error_page_eyebrow": {+ "message": "Επέκταση OmniGet"+ },+ "error_page_install_cta": {+ "message": "Εγκατάσταση του OmniGet"+ },+ "error_page_open_extensions": {+ "message": "Άνοιγμα επεκτάσεων Chrome"+ },+ "error_host_missing_title": {+ "message": "Ανοίξτε το OmniGet μία φορά για να ολοκληρώσετε τη ρύθμιση του Chrome"+ },+ "error_host_missing_body": {+ "message": "Το Chrome δεν μπόρεσε ακόμη να βρει τη γέφυρα OmniGet σε αυτόν τον υπολογιστή."+ },+ "error_host_missing_detail": {+ "message": "Εγκαταστήστε το OmniGet αν χρειάζεται, έπειτα ανοίξτε μία φορά την εφαρμογή υπολογιστή και πατήστε ξανά την επέκταση."+ },+ "error_invalid_url_title": {+ "message": "Η διεύθυνση URL αυτής της σελίδας δεν μπορεί να σταλεί στο OmniGet"+ },+ "error_invalid_url_body": {+ "message": "Η τρέχουσα σελίδα δεν είναι υποστηριζόμενη σελίδα πολυμέσων για την επέκταση OmniGet."+ },+ "error_invalid_url_detail": {+ "message": "Δοκιμάστε ξανά από μια άμεση σελίδα βίντεο, reel, ανάρτησης, λίστας αναπαραγωγής ή μαθήματος."+ },+ "error_launch_failed_title": {+ "message": "Το OmniGet δεν μπόρεσε να εκκινηθεί από το Chrome"+ },+ "error_launch_failed_body": {+ "message": "Η επέκταση επικοινώνησε με το native host, αλλά η εφαρμογή υπολογιστή δεν ξεκίνησε σωστά."+ },+ "error_launch_failed_detail": {+ "message": "Βεβαιωθείτε ότι το OmniGet είναι εγκατεστημένο και δεν έχει μπλοκαριστεί από τα Windows και δοκιμάστε ξανά."}}diff --git a/browser-extension/chrome/_locales/en/messages.json b/browser-extension/chrome/_locales/en/messages.jsonindex 1d631eba..b38f5727 100644--- a/browser-extension/chrome/_locales/en/messages.json+++ b/browser-extension/chrome/_locales/en/messages.json@@ -4,5 +4,44 @@},"action_title_unsupported": {"message": "No supported media detected on this page"+ },+ "error_page_document_title": {+ "message": "OmniGet Extension"+ },+ "error_page_eyebrow": {+ "message": "OmniGet Extension"+ },+ "error_page_install_cta": {+ "message": "Install OmniGet"+ },+ "error_page_open_extensions": {+ "message": "Open Chrome Extensions"+ },+ "error_host_missing_title": {+ "message": "Open OmniGet once to finish Chrome setup"+ },+ "error_host_missing_body": {+ "message": "Chrome could not find the OmniGet bridge on this computer yet."+ },+ "error_host_missing_detail": {+ "message": "Install OmniGet if needed, then launch the desktop app once and click the extension again."+ },+ "error_invalid_url_title": {+ "message": "This page URL cannot be sent to OmniGet"+ },+ "error_invalid_url_body": {+ "message": "The current page is not a supported media page for the OmniGet extension."+ },+ "error_invalid_url_detail": {+ "message": "Try again from a direct video, reel, post, playlist, or course page."+ },+ "error_launch_failed_title": {+ "message": "OmniGet could not be launched from Chrome"+ },+ "error_launch_failed_body": {+ "message": "The extension talked to the native host, but the desktop app did not start correctly."+ },+ "error_launch_failed_detail": {+ "message": "Check that OmniGet is installed and not blocked by Windows, then try again."}}diff --git a/browser-extension/chrome/_locales/fr/messages.json b/browser-extension/chrome/_locales/fr/messages.jsonindex efa1e535..a09baea2 100644--- a/browser-extension/chrome/_locales/fr/messages.json+++ b/browser-extension/chrome/_locales/fr/messages.json@@ -4,5 +4,44 @@},"action_title_unsupported": {"message": "Aucun média pris en charge détecté sur cette page"+ },+ "error_page_document_title": {+ "message": "Extension OmniGet"+ },+ "error_page_eyebrow": {+ "message": "Extension OmniGet"+ },+ "error_page_install_cta": {+ "message": "Installer OmniGet"+ },+ "error_page_open_extensions": {+ "message": "Ouvrir les extensions Chrome"+ },+ "error_host_missing_title": {+ "message": "Ouvrez OmniGet une fois pour terminer la configuration de Chrome"+ },+ "error_host_missing_body": {+ "message": "Chrome n'a pas encore trouvé le pont OmniGet sur cet ordinateur."+ },+ "error_host_missing_detail": {+ "message": "Installez OmniGet si nécessaire, puis lancez l'application de bureau une fois et cliquez à nouveau sur l'extension."+ },+ "error_invalid_url_title": {+ "message": "L'URL de cette page ne peut pas être envoyée à OmniGet"+ },+ "error_invalid_url_body": {+ "message": "La page actuelle n'est pas une page multimédia prise en charge par l'extension OmniGet."+ },+ "error_invalid_url_detail": {+ "message": "Réessayez depuis une page directe de vidéo, reel, publication, playlist ou cours."+ },+ "error_launch_failed_title": {+ "message": "OmniGet n'a pas pu être lancé depuis Chrome"+ },+ "error_launch_failed_body": {+ "message": "L'extension a bien contacté l'hôte natif, mais l'application de bureau ne s'est pas lancée correctement."+ },+ "error_launch_failed_detail": {+ "message": "Vérifiez qu'OmniGet est installé et non bloqué par Windows, puis réessayez."}}diff --git a/browser-extension/chrome/_locales/it/messages.json b/browser-extension/chrome/_locales/it/messages.jsonindex b6f22fea..c2fb66d2 100644--- a/browser-extension/chrome/_locales/it/messages.json+++ b/browser-extension/chrome/_locales/it/messages.json@@ -4,5 +4,44 @@},"action_title_unsupported": {"message": "Nessun contenuto multimediale supportato rilevato in questa pagina"+ },+ "error_page_document_title": {+ "message": "Estensione OmniGet"+ },+ "error_page_eyebrow": {+ "message": "Estensione OmniGet"+ },+ "error_page_install_cta": {+ "message": "Installa OmniGet"+ },+ "error_page_open_extensions": {+ "message": "Apri estensioni di Chrome"+ },+ "error_host_missing_title": {+ "message": "Apri OmniGet una volta per completare la configurazione di Chrome"+ },+ "error_host_missing_body": {+ "message": "Chrome non riesce ancora a trovare il bridge di OmniGet su questo computer."+ },+ "error_host_missing_detail": {+ "message": "Installa OmniGet se necessario, poi avvia una volta l'app desktop e fai di nuovo clic sull'estensione."+ },+ "error_invalid_url_title": {+ "message": "L'URL di questa pagina non può essere inviato a OmniGet"+ },+ "error_invalid_url_body": {+ "message": "La pagina corrente non è una pagina multimediale supportata dall'estensione OmniGet."+ },+ "error_invalid_url_detail": {+ "message": "Riprova da una pagina diretta di video, reel, post, playlist o corso."+ },+ "error_launch_failed_title": {+ "message": "OmniGet non è stato avviato da Chrome"+ },+ "error_launch_failed_body": {+ "message": "L'estensione ha comunicato con l'host nativo, ma l'app desktop non si è avviata correttamente."+ },+ "error_launch_failed_detail": {+ "message": "Verifica che OmniGet sia installato e non bloccato da Windows, poi riprova."}}diff --git a/browser-extension/chrome/_locales/ja/messages.json b/browser-extension/chrome/_locales/ja/messages.jsonindex 7dc902d0..4656f5e2 100644--- a/browser-extension/chrome/_locales/ja/messages.json+++ b/browser-extension/chrome/_locales/ja/messages.json@@ -4,5 +4,44 @@},"action_title_unsupported": {"message": "このページでは対応しているメディアが見つかりません"+ },+ "error_page_document_title": {+ "message": "OmniGet 拡張機能"+ },+ "error_page_eyebrow": {+ "message": "OmniGet 拡張機能"+ },+ "error_page_install_cta": {+ "message": "OmniGet をインストール"+ },+ "error_page_open_extensions": {+ "message": "Chrome 拡張機能を開く"+ },+ "error_host_missing_title": {+ "message": "Chrome のセットアップを完了するには OmniGet を一度開いてください"+ },+ "error_host_missing_body": {+ "message": "Chrome はこのコンピューター上の OmniGet ブリッジをまだ見つけられませんでした。"+ },+ "error_host_missing_detail": {+ "message": "必要なら OmniGet をインストールし、デスクトップアプリを一度起動してからもう一度拡張機能をクリックしてください。"+ },+ "error_invalid_url_title": {+ "message": "このページの URL は OmniGet に送信できません"+ },+ "error_invalid_url_body": {+ "message": "現在のページは OmniGet 拡張機能でサポートされているメディアページではありません。"+ },+ "error_invalid_url_detail": {+ "message": "動画、リール、投稿、再生リスト、またはコースの直接ページからもう一度お試しください。"+ },+ "error_launch_failed_title": {+ "message": "Chrome から OmniGet を起動できませんでした"+ },+ "error_launch_failed_body": {+ "message": "拡張機能はネイティブホストと通信しましたが、デスクトップアプリは正しく起動しませんでした。"+ },+ "error_launch_failed_detail": {+ "message": "OmniGet がインストールされていて Windows によってブロックされていないことを確認してから、もう一度お試しください。"}}diff --git a/browser-extension/chrome/_locales/pt/messages.json b/browser-extension/chrome/_locales/pt/messages.jsonindex 7f14c49c..6cd883fb 100644--- a/browser-extension/chrome/_locales/pt/messages.json+++ b/browser-extension/chrome/_locales/pt/messages.json@@ -4,5 +4,44 @@},"action_title_unsupported": {"message": "Nenhuma mídia compatível detectada nesta página"+ },+ "error_page_document_title": {+ "message": "Extensão OmniGet"+ },+ "error_page_eyebrow": {+ "message": "Extensão OmniGet"+ },+ "error_page_install_cta": {+ "message": "Instalar OmniGet"+ },+ "error_page_open_extensions": {+ "message": "Abrir extensões do Chrome"+ },+ "error_host_missing_title": {+ "message": "Abra o OmniGet uma vez para concluir a configuração do Chrome"+ },+ "error_host_missing_body": {+ "message": "O Chrome ainda não conseguiu encontrar a ponte do OmniGet neste computador."+ },+ "error_host_missing_detail": {+ "message": "Instale o OmniGet se necessário, depois abra o aplicativo de desktop uma vez e clique novamente na extensão."+ },+ "error_invalid_url_title": {+ "message": "A URL desta página não pode ser enviada ao OmniGet"+ },+ "error_invalid_url_body": {+ "message": "A página atual não é uma página de mídia compatível com a extensão OmniGet."+ },+ "error_invalid_url_detail": {+ "message": "Tente novamente a partir de uma página direta de vídeo, reel, publicação, playlist ou curso."+ },+ "error_launch_failed_title": {+ "message": "O OmniGet não pôde ser iniciado pelo Chrome"+ },+ "error_launch_failed_body": {+ "message": "A extensão falou com o host nativo, mas o aplicativo de desktop não iniciou corretamente."+ },+ "error_launch_failed_detail": {+ "message": "Verifique se o OmniGet está instalado e não foi bloqueado pelo Windows, depois tente novamente."}}diff --git a/browser-extension/chrome/_locales/zh_CN/messages.json b/browser-extension/chrome/_locales/zh_CN/messages.jsonindex a34f9d23..0170d9e4 100644--- a/browser-extension/chrome/_locales/zh_CN/messages.json+++ b/browser-extension/chrome/_locales/zh_CN/messages.json@@ -4,5 +4,44 @@},"action_title_unsupported": {"message": "此页面未检测到受支持的媒体"+ },+ "error_page_document_title": {+ "message": "OmniGet 扩展程序"+ },+ "error_page_eyebrow": {+ "message": "OmniGet 扩展程序"+ },+ "error_page_install_cta": {+ "message": "安装 OmniGet"+ },+ "error_page_open_extensions": {+ "message": "打开 Chrome 扩展程序"+ },+ "error_host_missing_title": {+ "message": "先打开一次 OmniGet 以完成 Chrome 设置"+ },+ "error_host_missing_body": {+ "message": "Chrome 目前还找不到这台电脑上的 OmniGet 桥接程序。"+ },+ "error_host_missing_detail": {+ "message": "如有需要请安装 OmniGet,然后先启动一次桌面应用,再次点击扩展程序。"+ },+ "error_invalid_url_title": {+ "message": "此页面 URL 无法发送到 OmniGet"+ },+ "error_invalid_url_body": {+ "message": "当前页面不是 OmniGet 扩展程序支持的媒体页面。"+ },+ "error_invalid_url_detail": {+ "message": "请从视频、Reel、帖子、播放列表或课程的直接页面重试。"+ },+ "error_launch_failed_title": {+ "message": "Chrome 无法启动 OmniGet"+ },+ "error_launch_failed_body": {+ "message": "扩展程序已与原生主机通信,但桌面应用未能正确启动。"+ },+ "error_launch_failed_detail": {+ "message": "请确认 OmniGet 已安装且未被 Windows 阻止,然后重试。"}}diff --git a/browser-extension/chrome/_locales/zh_TW/messages.json b/browser-extension/chrome/_locales/zh_TW/messages.jsonindex 34823f65..ef615707 100644--- a/browser-extension/chrome/_locales/zh_TW/messages.json+++ b/browser-extension/chrome/_locales/zh_TW/messages.json@@ -4,5 +4,44 @@},"action_title_unsupported": {"message": "此頁面未偵測到支援的媒體"+ },+ "error_page_document_title": {+ "message": "OmniGet 擴充功能"+ },+ "error_page_eyebrow": {+ "message": "OmniGet 擴充功能"+ },+ "error_page_install_cta": {+ "message": "安裝 OmniGet"+ },+ "error_page_open_extensions": {+ "message": "開啟 Chrome 擴充功能"+ },+ "error_host_missing_title": {+ "message": "請先開啟一次 OmniGet 以完成 Chrome 設定"+ },+ "error_host_missing_body": {+ "message": "Chrome 目前還找不到這台電腦上的 OmniGet 橋接程式。"+ },+ "error_host_missing_detail": {+ "message": "如有需要請安裝 OmniGet,然後先啟動一次桌面應用程式,再次點擊擴充功能。"+ },+ "error_invalid_url_title": {+ "message": "此頁面的 URL 無法傳送到 OmniGet"+ },+ "error_invalid_url_body": {+ "message": "目前頁面不是 OmniGet 擴充功能支援的媒體頁面。"+ },+ "error_invalid_url_detail": {+ "message": "請從影片、Reel、貼文、播放清單或課程的直接頁面再試一次。"+ },+ "error_launch_failed_title": {+ "message": "Chrome 無法啟動 OmniGet"+ },+ "error_launch_failed_body": {+ "message": "擴充功能已與原生主機通訊,但桌面應用程式未能正確啟動。"+ },+ "error_launch_failed_detail": {+ "message": "請確認 OmniGet 已安裝且未被 Windows 封鎖,然後再試一次。"}}diff --git a/browser-extension/chrome/manifest.json b/browser-extension/chrome/manifest.jsonindex d0fdf1d1..8fb26940 100644--- a/browser-extension/chrome/manifest.json+++ b/browser-extension/chrome/manifest.json@@ -14,11 +14,12 @@"type": "module"},"action": {- "default_title": "OmniGet",+ "default_title": "__MSG_action_title_unsupported__","default_icon": {"16": "icons/inactive-16.png","24": "icons/inactive-24.png",- "32": "icons/inactive-32.png"+ "32": "icons/inactive-32.png",+ "48": "icons/inactive-48.png"}},"icons": {diff --git a/browser-extension/chrome/pages/error-content.js b/browser-extension/chrome/pages/error-content.jsnew file mode 100644index 00000000..ddf23e15--- /dev/null+++ b/browser-extension/chrome/pages/error-content.js@@ -0,0 +1,72 @@+const ERROR_PAGE_MESSAGES = Object.freeze({+ error_page_document_title: "OmniGet Extension",+ error_page_eyebrow: "OmniGet Extension",+ error_page_install_cta: "Install OmniGet",+ error_page_open_extensions: "Open Chrome Extensions",+ error_host_missing_title: "Open OmniGet once to finish Chrome setup",+ error_host_missing_body: "Chrome could not find the OmniGet bridge on this computer yet.",+ error_host_missing_detail:+ "Install OmniGet if needed, then launch the desktop app once and click the extension again.",+ error_invalid_url_title: "This page URL cannot be sent to OmniGet",+ error_invalid_url_body:+ "The current page is not a supported media page for the OmniGet extension.",+ error_invalid_url_detail:+ "Try again from a direct video, reel, post, playlist, or course page.",+ error_launch_failed_title: "OmniGet could not be launched from Chrome",+ error_launch_failed_body:+ "The extension talked to the native host, but the desktop app did not start correctly.",+ error_launch_failed_detail:+ "Check that OmniGet is installed and not blocked by Windows, then try again.",+});++const ERROR_CODES = Object.freeze({+ HOST_MISSING: Object.freeze({+ title: "error_host_missing_title",+ body: "error_host_missing_body",+ detail: "error_host_missing_detail",+ }),+ INVALID_URL: Object.freeze({+ title: "error_invalid_url_title",+ body: "error_invalid_url_body",+ detail: "error_invalid_url_detail",+ }),+ LAUNCH_FAILED: Object.freeze({+ title: "error_launch_failed_title",+ body: "error_launch_failed_body",+ detail: "error_launch_failed_detail",+ }),+});++function defaultGetMessage(name) {+ if (typeof chrome === "undefined" || !chrome.i18n?.getMessage) {+ return "";+ }++ return chrome.i18n.getMessage(name);+}++function resolveMessage(name, getMessage) {+ return getMessage(name) || ERROR_PAGE_MESSAGES[name];+}++export function resolveErrorPageContent({+ code = "LAUNCH_FAILED",+ message = "",+ getMessage = defaultGetMessage,+} = {}) {+ const resolvedCode = Object.prototype.hasOwnProperty.call(ERROR_CODES, code)+ ? code+ : "LAUNCH_FAILED";+ const content = ERROR_CODES[resolvedCode];++ return {+ documentTitle: resolveMessage("error_page_document_title", getMessage),+ eyebrow: resolveMessage("error_page_eyebrow", getMessage),+ installLabel: resolveMessage("error_page_install_cta", getMessage),+ openExtensionsLabel: resolveMessage("error_page_open_extensions", getMessage),+ title: resolveMessage(content.title, getMessage),+ body: resolveMessage(content.body, getMessage),+ detail: message || resolveMessage(content.detail, getMessage),+ code: resolvedCode,+ };+}diff --git a/browser-extension/chrome/pages/error.css b/browser-extension/chrome/pages/error.cssindex 60b3ae10..023ddc8b 100644--- a/browser-extension/chrome/pages/error.css+++ b/browser-extension/chrome/pages/error.css@@ -84,7 +84,12 @@ h1 {justify-content: center;min-height: 42px;padding: 0 16px;+ border: none;border-radius: 999px;+ appearance: none;+ -webkit-appearance: none;+ cursor: pointer;+ font: inherit;color: #f5f7fb;text-decoration: none;background: rgba(255, 255, 255, 0.08);diff --git a/browser-extension/chrome/pages/error.html b/browser-extension/chrome/pages/error.htmlindex d40c709c..e309fb90 100644--- a/browser-extension/chrome/pages/error.html+++ b/browser-extension/chrome/pages/error.html@@ -9,7 +9,7 @@<body><main class="shell"><div class="card">- <p class="eyebrow">OmniGet Extension</p>+ <p id="eyebrow" class="eyebrow">OmniGet Extension</p><h1 id="title">Unable to hand this page to OmniGet</h1><p id="body" class="body"></p><p id="detail" class="detail"></p>diff --git a/browser-extension/chrome/pages/error.js b/browser-extension/chrome/pages/error.jsindex 1b0c8ce5..36c9a508 100644--- a/browser-extension/chrome/pages/error.js+++ b/browser-extension/chrome/pages/error.js@@ -1,3 +1,5 @@+import { resolveErrorPageContent } from "./error-content.js";+const params = new URLSearchParams(window.location.search);const code = params.get("code") ?? "LAUNCH_FAILED";@@ -5,45 +7,27 @@ const message = params.get("message") ?? "";const url = params.get("url") ?? "";const installUrl = params.get("installUrl") ?? "https://github.com/tonhowtf/omniget/releases/latest";+const eyebrow = document.getElementById("eyebrow");const title = document.getElementById("title");const body = document.getElementById("body");const detail = document.getElementById("detail");const urlNode = document.getElementById("url");const installLink = document.getElementById("install-link");-const openExtensionsBtn = document.getElementById("open-extensions");-const content = getContent(code);+const content = resolveErrorPageContent({ code, message });+document.title = content.documentTitle;+document.documentElement.lang = chrome.i18n?.getUILanguage?.() ?? "en";+eyebrow.textContent = content.eyebrow;title.textContent = content.title;body.textContent = content.body;-detail.textContent = message || content.detail;+detail.textContent = content.detail;urlNode.textContent = url;installLink.href = installUrl;+installLink.textContent = content.installLabel;+openExtensionsBtn.textContent = content.openExtensionsLabel;openExtensionsBtn.addEventListener("click", () => {chrome.tabs.create({ url: "chrome://extensions" });});--function getContent(errorCode) {- switch (errorCode) {- case "HOST_MISSING":- return {- title: "Open OmniGet once to finish Chrome setup",- body: "Chrome could not find the OmniGet bridge on this computer yet.",- detail: "Install OmniGet if needed, then launch the desktop app once and click the extension again.",- };- case "INVALID_URL":- return {- title: "This page URL cannot be sent to OmniGet",- body: "The current page is not a supported media page for the OmniGet extension.",- detail: "Try again from a direct video, reel, post, playlist, or course page.",- };- default:- return {- title: "OmniGet could not be launched from Chrome",- body: "The extension talked to the native host, but the desktop app did not start correctly.",- detail: "Check that OmniGet is installed and not blocked by Windows, then try again.",- };- }-}diff --git a/browser-extension/chrome/src/action-click.js b/browser-extension/chrome/src/action-click.jsnew file mode 100644index 00000000..93d735f2--- /dev/null+++ b/browser-extension/chrome/src/action-click.js@@ -0,0 +1,44 @@+const DEFAULT_LAUNCH_FAILED_CODE = "LAUNCH_FAILED";++export async function handleSupportedActionClick({+ tabId,+ url,+ sendNativeMessage,+ clearBadge = async () => {},+ showSuccessBadge = async () => {},+ openErrorPage,+ mapChromeErrorCode,+}) {+ if (tabId !== undefined && tabId !== null) {+ await clearBadge(tabId);+ }++ try {+ const response = await sendNativeMessage({+ type: "enqueue",+ url,+ });++ if (!response?.ok) {+ await openErrorPage({+ code: response?.code ?? DEFAULT_LAUNCH_FAILED_CODE,+ message: response?.message ?? "",+ url,+ });+ return false;+ }++ if (tabId !== undefined && tabId !== null) {+ await showSuccessBadge(tabId);+ }++ return true;+ } catch (error) {+ await openErrorPage({+ code: mapChromeErrorCode(error),+ message: error instanceof Error ? error.message : String(error),+ url,+ });+ return false;+ }+}diff --git a/browser-extension/chrome/src/action-feedback.js b/browser-extension/chrome/src/action-feedback.jsnew file mode 100644index 00000000..2aa35e4d--- /dev/null+++ b/browser-extension/chrome/src/action-feedback.js@@ -0,0 +1,71 @@+export const SUCCESS_BADGE_TEXT = "✓";+export const SUCCESS_BADGE_DURATION_MS = 1500;+export const SUCCESS_BADGE_BACKGROUND_COLOR = "#57b96a";++export function createActionFeedbackController({+ setBadgeText,+ setBadgeBackgroundColor = async () => {},+ setTimeoutFn = setTimeout,+ clearTimeoutFn = clearTimeout,+ durationMs = SUCCESS_BADGE_DURATION_MS,+ successText = SUCCESS_BADGE_TEXT,+ successColor = SUCCESS_BADGE_BACKGROUND_COLOR,+}) {+ const badgeTimeouts = new Map();++ function clearBadgeTimer(tabId) {+ const timeoutId = badgeTimeouts.get(tabId);+ if (timeoutId === undefined) {+ return;+ }++ clearTimeoutFn(timeoutId);+ badgeTimeouts.delete(tabId);+ }++ async function clearBadge(tabId) {+ if (tabId === undefined || tabId === null) {+ return;+ }++ clearBadgeTimer(tabId);+ await setBadgeText({+ tabId,+ text: "",+ });+ }++ async function showSuccessBadge(tabId) {+ if (tabId === undefined || tabId === null) {+ return;+ }++ clearBadgeTimer(tabId);++ await Promise.all([+ setBadgeBackgroundColor({+ tabId,+ color: successColor,+ }),+ setBadgeText({+ tabId,+ text: successText,+ }),+ ]);++ const timeoutId = setTimeoutFn(() => {+ badgeTimeouts.delete(tabId);+ void setBadgeText({+ tabId,+ text: "",+ });+ }, durationMs);++ badgeTimeouts.set(tabId, timeoutId);+ }++ return {+ clearBadge,+ showSuccessBadge,+ };+}diff --git a/browser-extension/chrome/src/background.js b/browser-extension/chrome/src/background.jsindex fdd49ee0..d16c72ad 100644--- a/browser-extension/chrome/src/background.js+++ b/browser-extension/chrome/src/background.js@@ -1,4 +1,6 @@import { detectSupportedMediaUrl } from "./detect.js";+import { handleSupportedActionClick } from "./action-click.js";+import { createActionFeedbackController } from "./action-feedback.js";import { resolveActionTitle } from "./action-title.js";const HOST_NAME = "wtf.tonho.omniget";@@ -6,14 +8,31 @@ const INSTALL_URL = "https://github.com/tonhowtf/omniget/releases/latest";function getIconPath(iconSet) {return {- 16: chrome.runtime.getURL(iconSet[0]),- 24: chrome.runtime.getURL(iconSet[1]),- 32: chrome.runtime.getURL(iconSet[2]),+ 16: chrome.runtime.getURL(iconSet[16]),+ 24: chrome.runtime.getURL(iconSet[24]),+ 32: chrome.runtime.getURL(iconSet[32]),+ 48: chrome.runtime.getURL(iconSet[48]),};}-const ACTIVE_ICON_PATHS = ["icons/active-16.png", "icons/active-24.png", "icons/active-32.png"];-const INACTIVE_ICON_PATHS = ["icons/inactive-16.png", "icons/inactive-24.png", "icons/inactive-32.png"];+const ACTIVE_ICON_PATHS = Object.freeze({+ 16: "icons/active-16.png",+ 24: "icons/active-24.png",+ 32: "icons/active-32.png",+ 48: "icons/active-48.png",+});++const INACTIVE_ICON_PATHS = Object.freeze({+ 16: "icons/inactive-16.png",+ 24: "icons/inactive-24.png",+ 32: "icons/inactive-32.png",+ 48: "icons/inactive-48.png",+});++const actionFeedback = createActionFeedbackController({+ setBadgeText: (details) => chrome.action.setBadgeText(details),+ setBadgeBackgroundColor: (details) => chrome.action.setBadgeBackgroundColor(details),+});chrome.runtime.onInstalled.addListener(() => {refreshActiveTab().catch(() => {});@@ -51,26 +70,15 @@ chrome.action.onClicked.addListener(async (tab) => {return;}- try {- const response = await sendNativeMessage({- type: "enqueue",- url: detected.url,- });-- if (!response?.ok) {- openErrorPage({- code: response?.code ?? "LAUNCH_FAILED",- message: response?.message ?? "OmniGet could not be launched from Chrome.",- url: detected.url,- });- }- } catch (error) {- openErrorPage({- code: mapChromeErrorCode(error),- message: error instanceof Error ? error.message : String(error),- url: detected.url,- });- }+ await handleSupportedActionClick({+ tabId: tab?.id,+ url: detected.url,+ sendNativeMessage,+ clearBadge: (tabId) => actionFeedback.clearBadge(tabId),+ showSuccessBadge: (tabId) => actionFeedback.showSuccessBadge(tabId),+ openErrorPage,+ mapChromeErrorCode,+ });});async function refreshActiveTab() {@@ -85,6 +93,12 @@ async function refreshActiveTab() {}async function refreshTabAction(tabId, tab) {+ try {+ await actionFeedback.clearBadge(tabId);+ } catch (error) {+ console.error("[OmniGet] Failed to clear badge:", error);+ }+if (!tab?.url) {return;}@@ -147,12 +161,16 @@ function mapChromeErrorCode(error) {function openErrorPage({ code, message, url }) {const params = new URLSearchParams({code,- installUrl: INSTALL_URL,- message,url,});- chrome.tabs.create({+ if (message) {+ params.set("message", message);+ }++ params.set("installUrl", INSTALL_URL);++ return chrome.tabs.create({url: `${chrome.runtime.getURL("pages/error.html")}?${params.toString()}`,});}diff --git a/browser-extension/chrome/tests/action-click.test.mjs b/browser-extension/chrome/tests/action-click.test.mjsnew file mode 100644index 00000000..1fd36c8b--- /dev/null+++ b/browser-extension/chrome/tests/action-click.test.mjs@@ -0,0 +1,88 @@+import test from "node:test";+import assert from "node:assert/strict";++import { handleSupportedActionClick } from "../src/action-click.js";++test("clears the previous badge and shows success feedback after a successful send", async () => {+ const calls = [];++ const result = await handleSupportedActionClick({+ tabId: 12,+ url: "https://example.com/watch?v=123",+ sendNativeMessage: async (message) => {+ calls.push(["send", message]);+ return { ok: true };+ },+ clearBadge: async (tabId) => {+ calls.push(["clear", tabId]);+ },+ showSuccessBadge: async (tabId) => {+ calls.push(["success", tabId]);+ },+ openErrorPage: async (details) => {+ calls.push(["error", details]);+ },+ mapChromeErrorCode: () => "LAUNCH_FAILED",+ });++ assert.equal(result, true);+ assert.deepEqual(calls, [+ ["clear", 12],+ ["send", { type: "enqueue", url: "https://example.com/watch?v=123" }],+ ["success", 12],+ ]);+});++test("does not show success feedback when the native host returns an error response", async () => {+ const calls = [];++ const result = await handleSupportedActionClick({+ tabId: 7,+ url: "https://example.com/reel/abc",+ sendNativeMessage: async () => ({ ok: false, code: "LAUNCH_FAILED" }),+ clearBadge: async (tabId) => {+ calls.push(["clear", tabId]);+ },+ showSuccessBadge: async (tabId) => {+ calls.push(["success", tabId]);+ },+ openErrorPage: async (details) => {+ calls.push(["error", details]);+ },+ mapChromeErrorCode: () => "LAUNCH_FAILED",+ });++ assert.equal(result, false);+ assert.deepEqual(calls, [+ ["clear", 7],+ ["error", { code: "LAUNCH_FAILED", message: "", url: "https://example.com/reel/abc" }],+ ]);+});++test("does not show success feedback when native messaging throws", async () => {+ const calls = [];++ const result = await handleSupportedActionClick({+ tabId: 3,+ url: "https://example.com/post/xyz",+ 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",+ });++ assert.equal(result, false);+ assert.deepEqual(calls, [+ ["clear", 3],+ ["error", { code: "HOST_MISSING", message: "host missing", url: "https://example.com/post/xyz" }],+ ]);+});diff --git a/browser-extension/chrome/tests/action-feedback.test.mjs b/browser-extension/chrome/tests/action-feedback.test.mjsnew file mode 100644index 00000000..5256a11a--- /dev/null+++ b/browser-extension/chrome/tests/action-feedback.test.mjs@@ -0,0 +1,120 @@+import test from "node:test";+import assert from "node:assert/strict";++import {+ SUCCESS_BADGE_BACKGROUND_COLOR,+ SUCCESS_BADGE_DURATION_MS,+ SUCCESS_BADGE_TEXT,+ createActionFeedbackController,+} from "../src/action-feedback.js";++function createFakeClock() {+ let nextId = 1;+ const timers = new Map();+ const cleared = [];++ return {+ cleared,+ clearTimeoutFn(timeoutId) {+ cleared.push(timeoutId);+ timers.delete(timeoutId);+ },+ getTimerIds() {+ return [...timers.keys()];+ },+ runTimer(timeoutId) {+ const timer = timers.get(timeoutId);+ assert.ok(timer, `timer ${timeoutId} should exist`);+ timers.delete(timeoutId);+ timer.callback();+ },+ setTimeoutFn(callback, delay) {+ const timeoutId = nextId;+ nextId += 1;+ timers.set(timeoutId, { callback, delay });+ return timeoutId;+ },+ };+}++test("shows a success badge and clears it after the default delay", async () => {+ const calls = [];+ const clock = createFakeClock();+ const controller = createActionFeedbackController({+ setBadgeText: async (details) => {+ calls.push(["text", details]);+ },+ setBadgeBackgroundColor: async (details) => {+ calls.push(["background", details]);+ },+ setTimeoutFn: clock.setTimeoutFn,+ clearTimeoutFn: clock.clearTimeoutFn,+ });++ await controller.showSuccessBadge(9);++ assert.deepEqual(calls, [+ ["background", { tabId: 9, color: SUCCESS_BADGE_BACKGROUND_COLOR }],+ ["text", { tabId: 9, text: SUCCESS_BADGE_TEXT }],+ ]);++ const [timeoutId] = clock.getTimerIds();+ assert.equal(clock.getTimerIds().length, 1);+ clock.runTimer(timeoutId);++ assert.deepEqual(calls.at(-1), ["text", { tabId: 9, text: "" }]);+});++test("resets the previous timer when a second success badge is shown for the same tab", async () => {+ const calls = [];+ const clock = createFakeClock();+ const controller = createActionFeedbackController({+ setBadgeText: async (details) => {+ calls.push(["text", details]);+ },+ setBadgeBackgroundColor: async (details) => {+ calls.push(["background", details]);+ },+ setTimeoutFn: clock.setTimeoutFn,+ clearTimeoutFn: clock.clearTimeoutFn,+ durationMs: SUCCESS_BADGE_DURATION_MS,+ });++ await controller.showSuccessBadge(4);+ const [firstTimeoutId] = clock.getTimerIds();++ await controller.showSuccessBadge(4);+ const [secondTimeoutId] = clock.getTimerIds();++ assert.deepEqual(clock.cleared, [firstTimeoutId]);+ assert.notEqual(secondTimeoutId, firstTimeoutId);+ assert.equal(clock.getTimerIds().length, 1);++ clock.runTimer(secondTimeoutId);++ const clearCalls = calls.filter(+ ([type, details]) => type === "text" && details.tabId === 4 && details.text === ""+ );+ assert.equal(clearCalls.length, 1);+});++test("clears any existing timer when the badge is explicitly cleared", async () => {+ const calls = [];+ const clock = createFakeClock();+ const controller = createActionFeedbackController({+ setBadgeText: async (details) => {+ calls.push(details);+ },+ setTimeoutFn: clock.setTimeoutFn,+ clearTimeoutFn: clock.clearTimeoutFn,+ });++ await controller.showSuccessBadge(2);+ const [timeoutId] = clock.getTimerIds();++ await controller.clearBadge(2);++ assert.deepEqual(clock.cleared, [timeoutId]);+ assert.deepEqual(calls.at(-1), { tabId: 2, text: "" });+ assert.equal(clock.getTimerIds().length, 0);+});diff --git a/browser-extension/chrome/tests/error-content.test.mjs b/browser-extension/chrome/tests/error-content.test.mjsnew file mode 100644index 00000000..8428904d--- /dev/null+++ b/browser-extension/chrome/tests/error-content.test.mjs@@ -0,0 +1,63 @@+import test from "node:test";+import assert from "node:assert/strict";++import { resolveErrorPageContent } from "../pages/error-content.js";++test("uses localized page strings when locale messages are available", () => {+ const localized = {+ error_page_document_title: "Extension OmniGet",+ error_page_eyebrow: "Extension OmniGet",+ error_page_install_cta: "Installer OmniGet",+ error_page_open_extensions: "Ouvrir les extensions Chrome",+ error_host_missing_title: "Titre localise",+ error_host_missing_body: "Corps localise",+ error_host_missing_detail: "Detail localise",+ };++ const content = resolveErrorPageContent({+ code: "HOST_MISSING",+ getMessage: (name) => localized[name] ?? "",+ });++ assert.equal(content.documentTitle, "Extension OmniGet");+ assert.equal(content.eyebrow, "Extension OmniGet");+ assert.equal(content.installLabel, "Installer OmniGet");+ assert.equal(content.openExtensionsLabel, "Ouvrir les extensions Chrome");+ assert.equal(content.title, "Titre localise");+ assert.equal(content.body, "Corps localise");+ assert.equal(content.detail, "Detail localise");+});++test("falls back to English when locale messages are missing", () => {+ const content = resolveErrorPageContent({+ code: "INVALID_URL",+ getMessage: () => "",+ });++ assert.equal(content.documentTitle, "OmniGet Extension");+ assert.equal(content.title, "This page URL cannot be sent to OmniGet");+ assert.equal(+ content.detail,+ "Try again from a direct video, reel, post, playlist, or course page."+ );+});++test("prefers the query message for detail text when one is provided", () => {+ const content = resolveErrorPageContent({+ code: "LAUNCH_FAILED",+ message: "Desktop launch failed with exit code 5",+ getMessage: () => "",+ });++ assert.equal(content.detail, "Desktop launch failed with exit code 5");+});++test("falls back to LAUNCH_FAILED content for unknown error codes", () => {+ const content = resolveErrorPageContent({+ code: "SOMETHING_NEW",+ getMessage: () => "",+ });++ assert.equal(content.code, "LAUNCH_FAILED");+ assert.equal(content.title, "OmniGet could not be launched from Chrome");+});diff --git a/browser-extension/chrome/tests/manifest.test.mjs b/browser-extension/chrome/tests/manifest.test.mjsnew file mode 100644index 00000000..c00e079b--- /dev/null+++ b/browser-extension/chrome/tests/manifest.test.mjs@@ -0,0 +1,21 @@+import test from "node:test";+import assert from "node:assert/strict";+import { readFile } from "node:fs/promises";++const manifestUrl = new URL("../manifest.json", import.meta.url);++async function readManifest() {+ return JSON.parse(await readFile(manifestUrl, "utf8"));+}++test("localizes the default action title through manifest i18n", async () => {+ const manifest = await readManifest();++ assert.equal(manifest.action.default_title, "__MSG_action_title_unsupported__");+});++test("declares the 48px toolbar icon for the inactive action state", async () => {+ const manifest = await readManifest();++ assert.equal(manifest.action.default_icon["48"], "icons/inactive-48.png");+});diff --git a/src-tauri/src/native_host.rs b/src-tauri/src/native_host.rsindex 3d23af54..08917913 100644--- a/src-tauri/src/native_host.rs+++ b/src-tauri/src/native_host.rs@@ -7,7 +7,11 @@ use anyhow::Context;use serde::{Deserialize, Serialize};pub const CHROME_HOST_NAME: &str = "wtf.tonho.omniget";-pub const CHROME_EXTENSION_ID: &str = "dkjelkhaaakffpghdfalobccaaipajip";+pub const CHROME_EXTENSION_IDS: &[&str] = &[+ // Unpacked development extension ID derived from browser-extension/chrome/manifest.json.+ "dkjelkhaaakffpghdfalobccaaipajip",+ // Add the Chrome Web Store extension ID here once it is assigned.+];#[cfg(target_os = "windows")]const HOST_COPY_NAME: &str = "omniget-native-host.exe";@@ -108,12 +112,17 @@ fn build_host_manifest(host_exe: &Path) -> serde_json::Value {"description": "OmniGet native host for Chrome","path": host_exe.to_string_lossy().to_string(),"type": "stdio",- "allowed_origins": [- format!("chrome-extension://{}/", CHROME_EXTENSION_ID)- ]+ "allowed_origins": chrome_allowed_origins()})}+fn chrome_allowed_origins() -> Vec<String> {+ CHROME_EXTENSION_IDS+ .iter()+ .map(|extension_id| format!("chrome-extension://{extension_id}/"))+ .collect()+}+#[cfg(target_os = "windows")]fn chrome_manifest_path(integration_dir: &Path) -> anyhow::Result<PathBuf> {Ok(chrome_manifest_path_from_base(integration_dir))@@ -361,9 +370,17 @@ mod tests {assert_eq!(manifest["description"].as_str(), Some("OmniGet native host for Chrome"));assert_eq!(manifest["path"].as_str(), Some(host_exe.to_string_lossy().as_ref()));assert_eq!(manifest["type"].as_str(), Some("stdio"));- assert_eq!(- manifest["allowed_origins"][0].as_str(),- Some(format!("chrome-extension://{CHROME_EXTENSION_ID}/").as_str())- );+ let allowed_origins = manifest["allowed_origins"]+ .as_array()+ .expect("allowed_origins should be an array");++ assert_eq!(allowed_origins.len(), CHROME_EXTENSION_IDS.len());++ for (origin, extension_id) in allowed_origins.iter().zip(CHROME_EXTENSION_IDS.iter()) {+ assert_eq!(+ origin.as_str(),+ Some(format!("chrome-extension://{extension_id}/").as_str())+ );+ }}}