I maintain CutThisX, a free web tool that cuts a part of an online video from its link and downloads only that part. Last week I shipped version 1.1 of its browser extension, whose whole job is a small "Cut" button on top of videos. A button on a video sounds trivial. Doing it in Manifest V3 without asking for scary permissions at install time was not. Here is what I ended up with.
1. Two kinds of sites, two permission levels
The button is on by default on the video sites the tool supports. Those hosts are listed in host_permissions, so the user sees them at install and nothing more.
The new option "Also on other websites" needs access to every site. That one lives in optional_host_permissions and is only requested when the user flips the switch in the popup:
// popup.js all.addEventListener('change', () => { if (!all.checked) return chrome.permissions.remove({ origins: ['*://*/*'] }, refresh); chrome.permissions.request({ origins: ['*://*/*'] }, (granted) => { if (granted) chrome.storage.local.set({ buttons: true }, refresh); }); }); permissions.request must run inside a user gesture, so it has to be called from the popup's click handler, not from the service worker.
2. Content scripts registered at runtime, not in the manifest
A static content_scripts entry for *://*/* would make the store show "read and change all your data" at install, which is exactly what I wanted to avoid. Instead the service worker registers the scripts itself, and only for the origins it currently holds:
// background.js async function keepScript(id, wanted, spec) { const existing = await chrome.scripting.getRegisteredContentScripts({ ids: [id] }); if (wanted && !existing.length) { await chrome.scripting.registerContentScripts([{ id, js: BUTTON_FILES, runAt: 'document_idle', persistAcrossSessions: true, ...spec }]); } else if (!wanted && existing.length) { await chrome.scripting.unregisterContentScripts({ ids: [id] }); } } async function syncButtons() { const { buttons } = await chrome.storage.local.get({ buttons: true }); const platforms = buttons && (await chrome.permissions.contains({ origins: siteOrigins() })); const web = buttons && (await chrome.permissions.contains({ origins: ['*://*/*'] })); await keepScript('cutthisx-buttons', platforms, { matches: siteOrigins() }); await keepScript('cutthisx-buttons-web', web, { matches: ['*://*/*'], excludeMatches: [...siteOrigins(), ...neverHosts()] }); } chrome.storage.onChanged.addListener(syncButtons); chrome.permissions.onAdded.addListener(syncButtons); chrome.permissions.onRemoved.addListener(syncButtons); Two details that cost me time:
-
excludeMatcheson the "all sites" script. Without it, the supported video sites get both scripts and two buttons per video. - Listen to
permissions.onRemoved. Users can revoke site access from the browser's own extension page, not only from your popup. If you do not listen, your registered script outlives the permission and silently stops working.
3. Feeds do not have a URL per video
On a watch page, the link to send is location.href. In a feed (a vertical video feed, a timeline, a Reels tab) the address bar does not change while you scroll, so location.href points at the feed, not the video under the cursor. The content script walks up from the <video> element to the post that contains it and takes the first link inside that post that looks like a video permalink:
function linkIn(box, filter) { for (const a of box.querySelectorAll('a[href]')) { if (filter && !filter(a)) continue; const href = new URL(a.getAttribute('href'), location.href).href; if (detectPlatform(href)) return href; } return null; } On "other websites" there is no permalink to find, so the button simply sends the page URL.
4. The store reviews read your justifications
Chrome, Edge and Firefox each ask why you need every permission. Short, concrete answers worked best for me: what triggers it ("when the user clicks the toolbar button"), what is read ("the address of the current tab"), and what is not ("no page content is collected or sent"). Edge also wants certification notes with every single submission, even a minor update.
Result
- Install shows only the supported video sites.
- "All websites" is one switch away, asked for once, and removable.
- No content script runs on a site the user has not allowed.
The extension is free for Chrome, Firefox and Edge, and the extension page shows what the button does. The web tool itself works without it: paste a link on cutthisx.com, pick the start and end, download the part as MP4 or MP3.
If you have built something similar, I would like to know how you handled feeds.
