From 77793c8c6e051209c9bf3352b8222d39d8c46a3b Mon Sep 17 00:00:00 2001 From: KoalaDev <6156589+Shik3i@users.noreply.github.com> Date: Sat, 13 Jun 2026 21:01:31 +0200 Subject: [PATCH] feat(extension): setup cross-browser uninstall url architecture --- docs/CHANGELOG.md | 1 + extension/background.js | 27 +++++++++++++++++++++++++++ scripts/build-extension.js | 26 ++++++++++++++++++++++++-- 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 0114cf1..ee42837 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -9,6 +9,7 @@ All notable changes to the KoalaSync browser extension and relay server. ### Added - **Extension: New Interactive Onboarding Tour**: A fully redesigned, interactive step-by-step onboarding experience. - **Extension: Auto-Switch to Sync Tab**: The UI now intelligently switches to the Sync tab when you join a room to guide video selection. +- **Extension: Uninstall URL Integration**: Prepared an uninstall URL setup that works natively across Chrome and Firefox, cleanly attaching browser context for analytics. ### Fixed - **Extension: Infinite Seek Loop Prevention**: Replaced the fragile time-based seek suppression with an exact target-time verification mechanism, entirely eliminating infinite seek loops on slow buffers. diff --git a/extension/background.js b/extension/background.js index f773c91..f8c4aa0 100644 --- a/extension/background.js +++ b/extension/background.js @@ -2,6 +2,33 @@ import { EVENTS, PROTOCOL_VERSION, OFFICIAL_SERVER_URL, OFFICIAL_SERVER_TOKEN, E import { generateUsername } from './shared/names.js'; import { loadLocale, getMessage, getSystemLanguage } from './i18n.js'; +// --- Uninstall URL Initialization --- +chrome.runtime.onInstalled.addListener((details) => { + if (details.reason === 'install' || details.reason === 'update') { + // --- UNINSTALL_URL_INJECT_START --- + const UNINSTALL_URL = ""; // Populated during build + const BROWSER_TYPE = "unknown"; + // --- UNINSTALL_URL_INJECT_END --- + + if (UNINSTALL_URL && UNINSTALL_URL.trim() !== '') { + try { + const url = new URL(UNINSTALL_URL); + url.searchParams.set("browser", BROWSER_TYPE); + + const runtimeAPI = typeof browser !== 'undefined' ? browser.runtime : chrome.runtime; + if (runtimeAPI && runtimeAPI.setUninstallURL) { + const result = runtimeAPI.setUninstallURL(url.href); + // browser.runtime.setUninstallURL returns a Promise, handle rejection silently + if (result && typeof result.catch === 'function') { + result.catch(err => console.warn('Failed to set uninstall URL:', err)); + } + } + } catch (err) { + console.error("Invalid uninstall URL provided:", err); + } + } + } +}); // --- State Management --- let socket = null; diff --git a/scripts/build-extension.js b/scripts/build-extension.js index 31912eb..3709925 100644 --- a/scripts/build-extension.js +++ b/scripts/build-extension.js @@ -38,7 +38,7 @@ const baseManifest = JSON.parse(fs.readFileSync(baseManifestPath, 'utf8')); // Helper to copy files, ignoring manifest.json and manifest.base.json // Also injects shared constants into content.js -function copyExtensionFiles(targetDir) { +function copyExtensionFiles(targetDir, browserName) { fs.mkdirSync(targetDir, { recursive: true }); // Read master constants for injection @@ -99,6 +99,28 @@ function copyExtensionFiles(targetDir) { fs.writeFileSync(destPath, content); console.log('✓ Injected shared constants into content.js'); + } else if (item === 'background.js') { + let content = fs.readFileSync(srcPath, 'utf8'); + + // 3. Inject Uninstall URL Constants + const uStart = '// --- UNINSTALL_URL_INJECT_START ---'; + const uEnd = '// --- UNINSTALL_URL_INJECT_END ---'; + const uPattern = new RegExp(`${uStart}[\\s\\S]+?${uEnd}`); + const placeholderUrl = "https://example.com/uninstall-placeholder"; // TODO: Replace me + + let uRep = `${uStart}\n // This block is automatically updated by /scripts/build-extension.js\n`; + uRep += ` const UNINSTALL_URL = "${placeholderUrl}";\n`; + uRep += ` const BROWSER_TYPE = "${browserName}";\n`; + uRep += ` ${uEnd}`; + + if (uPattern.test(content)) { + content = content.replace(uPattern, uRep); + } else { + console.warn('⚠️ WARNING: Uninstall URL markers not found in background.js'); + } + + fs.writeFileSync(destPath, content); + console.log(`✓ Injected uninstall URL constants for ${browserName} into background.js`); } else { fs.copyFileSync(srcPath, destPath); } @@ -127,7 +149,7 @@ async function buildBrowser(browserName, manifestModifier) { const browserDistDir = path.join(distDir, browserName); // 1. Copy files - copyExtensionFiles(browserDistDir); + copyExtensionFiles(browserDistDir, browserName); // 2. Modify and write manifest const browserManifest = manifestModifier(JSON.parse(JSON.stringify(baseManifest)));