SundayPyjamas Adblocker is a Chrome extension designed to block advertisements and tracking scripts from various known ad networks and analytics services. This extension is built with privacy in mind and uses Chrome's Manifest V3 architecture.
The main components of this extension are:
manifest.json: Defines the extension's properties, permissions, and structure.background.js: Contains the core functionality of the adblocker.README.md: This file, providing documentation for the project.
This extension uses Manifest V3, which is the latest version of Chrome's extension architecture. Manifest V3 was introduced to improve extension security, privacy, and performance. Key features of Manifest V3 include:
- Use of service workers instead of background pages
- Improved declarative APIs for content blocking
- More secure handling of extension permissions
"manifest_version": 3The manifest.json file defines the extension's properties and capabilities:
{
"name": "SundayPyjamas Adblocker",
"version": "1.0",
"description": "Private by Design, A SundayPyjamas Product"
}The extension requires the following permissions:
"permissions": [
"declarativeNetRequest",
"declarativeNetRequestFeedback",
"*://*.doubleclick.net/*",
"*://partner.googleadservices.com/*",
"*://*.googlesyndication.com/*",
"*://*.google-analytics.com/*",
"*://creative.ak.fbcdn.net/*",
"*://*.adbrite.com/*",
"*://*.exponential.com/*",
"*://*.quantserve.com/*",
"*://*.scorecardresearch.com/*",
"*://*.zedo.com/*"
]declarativeNetRequest: Allows the extension to use declarative rules to block network requests.declarativeNetRequestFeedback: Provides feedback on matched declarative rules.- The other permissions are specific domains known for serving ads and tracking scripts.
The extension uses a service worker as its background script:
"background": {
"service_worker": "background.js"
}This indicates that the core functionality of the adblocker is implemented in the background.js file.
The extension includes a 128x128 pixel icon:
"icons": {
"128": "icons/logo_128x128.png"
}The background.js file contains the core logic for the adblocker. It likely uses the declarativeNetRequest API to define rules for blocking requests to the specified ad and tracking domains. This API allows for efficient, declarative blocking of network requests without the need for a persistent background page.
To work on this extension:
- Clone the repository containing these files.
- Open Chrome and navigate to
chrome://extensions. - Enable "Developer mode" in the top right corner.
- Click "Load unpacked" and select the directory containing the manifest.json and background.js files.
To enhance this adblocker:
- Review and optimize the blocking logic in
background.js. - Consider adding a user interface for enabling/disabling the adblocker or customizing blocking rules.
- Expand the list of blocked domains as needed.
- Implement logging or analytics to track the number of blocked requests (ensuring user privacy is maintained).
- Consider implementing optional features like whitelisting for trusted sites.