Adding a Cut button to videos on every site in Manifest V3, without scary install permissions
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…
CutThisX is a free web tool that allows users to cut specific parts of online videos by providing a "Cut" button on top of the video. The tool recently released version 1.1 of its browser extension, which introduced a small "Cut" button on videos without requiring users to grant scary permissions at install time. The extension functions on two types of websites with different permission levels: video hosting sites and other websites.
In popup.js, the addEventListener listens for changes to a checkbox. If the checkbox is unchecked, the script removes all permissions using chrome.permissions.remove, and if it is checked, the script requests permissions for all websites using chrome.permissions.request. The request must be made from the popup's click handler, not from the service worker, as content scripts can only run from user gestures.
Content scripts are not registered in the manifest due to concerns over privacy permissions at install time. Instead, the service worker registers the scripts dynamically based on the origins currently being accessed. The syncButtons function checks for permissions and registers content scripts accordingly. The "all sites" script includes an excludeMatches option to prevent multiple buttons from appearing on supported video sites.
Feeds, or vertical video feeds, present a unique challenge as their URLs do not change while scrolling. To address this, the content script walks up from the video element to the post containing it and extracts the first link within that post that appears to be a video permalink.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to