/safariextension.mym

BLOCK WEBSITE PATHS like YouTube shorts

safariextension.mym

BLOCK WEBSITE PATHS like YouTube shorts

Safari Extension: Block YouTube Shorts This document provides instructions on how to create a Safari Web Extension to block specific URL paths such as 'https://www.youtube.com/shorts/'. This project leverages the Safari Web Extensions API and WebExtensions framework.

  1. Set Up Development Environment
  2. Install Xcode from the Mac App Store.
  3. Enable Safari Developer Tools:
  • Open Safari.
  • Go to Safari > Preferences > Advanced.
  • Enable 'Show Develop menu in menu bar'.
  1. Create a Safari Web Extension Project
  2. Open Xcode.
  3. Create a new project: File > New > Project.
  4. Select 'Safari Web Extension' and configure the bundle identifier.
  5. Define Blocking Logic in JavaScript Add the following logic in a 'background.js' script to listen for network requests and block paths containing '/shorts/': browser.webRequest.onBeforeRequest.addListener( function (details) { if (details.url.includes('/shorts/')) { console.log('Blocking:', details.url); return { cancel: true }; } },

{ urls: ['://.youtube.com/'] }, ['blocking'] ); 4. Set Up manifest.json Add the following 'manifest.json' file to describe your extension's permissions and functionality: { 'manifest_version': 2, 'name': 'Block YouTube Shorts', 'version': '1.0', 'description': 'Blocks access to YouTube Shorts', 'permissions': [ 'webRequest', 'webRequestBlocking', 'tabs', '://.youtube.com/' ], 'background': { 'scripts': ['background.js'] } } 5. Test Your Extension

  1. Build and run your extension in Xcode.

  2. Safari will launch with your extension loaded for testing.

  3. Enable and Debug the Extension

  4. Open Safari and go to Safari > Preferences > Extensions.

  5. Enable your extension.

  6. Use the Develop menu to debug and check logs. Resources