popup-blocker-chrome-extension

Popup Blocker Chrome Extension

A Chrome extension for blocking unnecessary content on web pages, with extensible rule support.

🎯 Project Status

βœ… Core functionality completed: Block onetrust-consent-sdk.js script

✨ Features

Implemented:

  1. βœ… Block onetrust-consent-sdk.js script to prevent privacy policy notifications
  2. βœ… Multi-layer interception mechanism:
    • declarativeNetRequest network layer interception
    • MutationObserver DOM layer interception
    • Periodic cleanup of loaded OneTrust elements
  3. βœ… Automatically remove OneTrust-related popups and banners
  4. βœ… Restore disabled page scrolling functionality

Not Implemented (Future):

πŸ“¦ Installation

  1. Open Chrome Extensions Page

    • Enter in address bar: chrome://extensions/
    • Or via menu: More Tools β†’ Extensions
  2. Enable Developer Mode

    • Toggle β€œDeveloper mode” switch in top-right corner
  3. Load Extension

    • Click β€œLoad unpacked” button
    • Select this project directory (the folder containing manifest.json)
  4. Confirm Installation

    • Extension list should display β€œPopup Blocker”
    • Status should be enabled (blue toggle)

Method 2: Packaged Installation

# In Chrome Extensions management page
# Click "Pack extension"
# Select this project root directory
# Install the generated .crx file

πŸš€ Usage

  1. After installation, the extension runs automatically on all web pages
  2. Visit any website with OneTrust privacy popups (many international sites)
  3. The extension automatically blocks privacy notifications - no manual action needed
  4. View [Popup Blocker] logs in browser console for interception details

πŸ” How It Works

The extension uses three layers of protection:

1. Network Layer Interception (declarativeNetRequest API)

Blocks script requests from the following domains:

Intercepts before script download for maximum efficiency.

2. DOM Monitoring (MutationObserver)

3. Periodic Cleanup (setInterval)

πŸ§ͺ Testing

Test Websites

Expected Results

View Logs

  1. Open browser developer tools (F12 or Cmd+Option+I)
  2. Switch to β€œConsole” tab
  3. Look for log messages with [Popup Blocker] prefix

Example logs:

[Popup Blocker] Content script loaded
[Popup Blocker] Blocked script: https://cdn.cookielaw.org/scripttemplates/otSDKStub.js
[Popup Blocker] Removed element: #onetrust-consent-sdk

πŸ› οΈ Technical Implementation

Files

Key Code Snippets

manifest.json Configuration

{
  "manifest_version": 3,
  "permissions": ["declarativeNetRequest"],
  "host_permissions": ["<all_urls>"],
  "declarative_net_request": {
    "rule_resources": [
      {
        "id": "ruleset_1",
        "enabled": true,
        "path": "rules.json"
      }
    ]
  },
  "content_scripts": [
    {
      "matches": ["<all_urls>"],
      "js": ["content.js"],
      "run_at": "document_start"
    }
  ]
}

content.js Core Logic

// DOM monitoring
const observer = new MutationObserver(mutations => {
  mutations.forEach(mutation => {
    mutation.addedNodes.forEach(node => {
      if (node.tagName === "SCRIPT") {
        const src = node.src || "";
        if (src.includes("onetrust-consent-sdk") || src.includes("cdn.cookielaw.org")) {
          console.log("[Popup Blocker] Blocked script:", src);
          node.remove();
        }
      }
    });
  });
});

// Periodic cleanup
function removeOneTrustElements() {
  const selectors = ["#onetrust-consent-sdk", "#onetrust-banner-sdk", "#onetrust-pc-sdk", ".onetrust-pc-dark-filter"];
  selectors.forEach(selector => {
    document.querySelectorAll(selector).forEach(el => el.remove());
  });
  document.body.style.overflow = "";
}
setInterval(removeOneTrustElements, 500);

πŸ“ Project Structure

popups-blocker-chrome-extension/
β”œβ”€β”€ manifest.json          # Extension configuration (Manifest V3)
β”œβ”€β”€ content.js            # Content script (2.2KB)
β”œβ”€β”€ rules.json            # declarativeNetRequest rules
β”œβ”€β”€ README.md             # Project documentation
β”œβ”€β”€ icons/                # Icon resources
β”‚   β”œβ”€β”€ icon16.png        # 16x16 icon
β”‚   β”œβ”€β”€ icon48.png        # 48x48 icon
β”‚   β”œβ”€β”€ icon128.png       # 128x128 icon
β”‚   └── icon.svg          # SVG source file
└── verify.sh             # Verification script

πŸ“Š Performance Metrics

πŸ”§ Development & Debugging

Reload Extension After Code Changes

  1. Modify code files (manifest.json, content.js, rules.json)
  2. Go to chrome://extensions/
  3. Find Popup Blocker extension card
  4. Click refresh icon πŸ”„
  5. Refresh test webpage to see effects

Debugging Tips

  1. View Interception Logs

    Open Console (F12) β†’ Filter "[Popup Blocker]"
    
  2. Test Network Interception

    Open Network tab β†’ Look for cancelled requests
    
  3. Verify DOM Cleanup

    Open Elements tab β†’ Search "onetrust"
    Should find no related elements
    

Common Issues

Q: Extension not working?

Q: How to temporarily disable extension?

Q: How to uninstall extension?

🎨 Custom Icons (Optional)

Current placeholder icons can be customized:

cd icons
# Method 1: Use ImageMagick
brew install imagemagick
convert icon.svg -resize 16x16 icon16.png
convert icon.svg -resize 48x48 icon48.png
convert icon.svg -resize 128x128 icon128.png

# Method 2: Use online tools
# Visit https://www.aconvert.com/image/svg-to-png/
# Upload icon.svg and generate different sizes

βš™οΈ Technical Stack

πŸ“ Technical Details

πŸ“œ License

MIT License - Free to use and modify


Project Created: November 24, 2025
Minimum Chrome Version: 88+
Status: βœ… Production Ready