Skip to content

convert wBlock Advanced to shared web extension#282

Merged
0xCUB3 merged 3 commits intomainfrom
web-extension-migration
Mar 17, 2026
Merged

convert wBlock Advanced to shared web extension#282
0xCUB3 merged 3 commits intomainfrom
web-extension-migration

Conversation

@0xCUB3
Copy link
Copy Markdown
Owner

@0xCUB3 0xCUB3 commented Mar 17, 2026

Replaces the macOS Safari App Extension (wBlock Advanced) with a Safari Web Extension that shares all JS, HTML, and Swift handler code with the iOS extension. Fixes #223.

  • New macOS web extension target references wBlock Scripts (iOS)/Resources/ directly, no code duplication
  • declarativeNetRequest rules to strip CSP headers on youtube.com so scriptlets can inject
  • Fix MainActor deadlock in checkForUpdates that caused "Checking for updates..." to hang forever during Apply Changes (pre-fetch validators before entering task group, defer writes until after)
  • Remove broken Refresh button from element zapper popup, Clear now reloads the page
  • Add tabs permission to manifest for popup-to-content-script messaging on macOS
  • Wider popup on macOS (min-width: 340px)

replaces the macOS-only Safari App Extension with a Safari Web Extension
that shares all JS/HTML resources with the iOS extension. adds
declarativeNetRequest rules to strip CSP headers on YouTube for scriptlet
injection. fixes MainActor deadlock in checkForUpdates that froze the app
during apply changes. removes broken refresh button from element zapper
popup, clear now reloads the page.
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the macOS extension by migrating it from a traditional Safari App Extension to a modern Safari Web Extension. This change streamlines development by allowing code sharing between macOS and iOS platforms, addresses critical functional issues like update deadlocks, and enhances web compatibility by dynamically modifying CSP headers for specific sites. The user interface for the element zapper also received minor improvements for clarity and responsiveness.

Highlights

  • Migration to Safari Web Extension: The macOS Safari App Extension (wBlock Advanced) has been replaced with a Safari Web Extension, enabling shared code (JS, HTML, Swift) with the iOS extension and fixing issue [BUG] YouTube Ads still popping up after new update. #223.
  • CSP Header Stripping for YouTube: New declarativeNetRequest rules have been implemented to strip Content Security Policy (CSP) headers on youtube.com, which is crucial for successful scriptlet injection.
  • Deadlock Fix in Update Checking: A MainActor deadlock that caused the 'Checking for updates...' process to hang during 'Apply Changes' has been resolved by pre-fetching validators before task group entry and deferring writes.
  • Element Zapper UI Improvements: The broken 'Refresh' button has been removed from the element zapper popup, and the 'Clear' action now reloads the page for immediate effect.
  • Enhanced Web Extension Capabilities: The manifest has been updated to include 'tabs' permission for popup-to-content-script messaging on macOS, and the popup's minimum width has been increased to 340px for a better user experience.
Changelog
  • .gitignore
    • Added 'docs/superpowers/' to the ignore list.
  • wBlock Advanced/Base.lproj/SafariExtensionViewController.xib
    • Removed the old Safari App Extension's view controller XIB file.
  • wBlock Advanced/Info.plist
    • Removed the Info.plist file for the deprecated wBlock Advanced Safari App Extension.
  • wBlock Advanced/PopoverView.swift
    • Removed the SwiftUI popover view specific to the old Safari App Extension.
  • wBlock Advanced/PopoverViewModel.swift
    • Removed the view model for the old Safari App Extension's popover.
  • wBlock Advanced/Resources/userscript-injector.js
    • Removed the userscript injector JavaScript file from the old extension.
  • wBlock Advanced/SafariExtensionHandler.swift
    • Removed the Safari App Extension handler Swift file.
  • wBlock Advanced/SafariExtensionViewController.swift
    • Removed the Safari App Extension view controller Swift file.
  • wBlock Advanced/ToolbarData.swift
    • Removed the toolbar data management logic specific to the old extension.
  • wBlock Advanced/ar.lproj/Localizable.strings
    • Removed Arabic localization strings for the old extension.
  • wBlock Advanced/de.lproj/Localizable.strings
    • Removed German localization strings for the old extension.
  • wBlock Advanced/el.lproj/Localizable.strings
    • Removed Greek localization strings for the old extension.
  • wBlock Advanced/en.lproj/Localizable.strings
    • Removed English localization strings for the old extension.
  • wBlock Advanced/es.lproj/Localizable.strings
    • Removed Spanish localization strings for the old extension.
  • wBlock Advanced/fr.lproj/Localizable.strings
    • Removed French localization strings for the old extension.
  • wBlock Advanced/hu.lproj/Localizable.strings
    • Removed Hungarian localization strings for the old extension.
  • wBlock Advanced/it.lproj/Localizable.strings
    • Removed Italian localization strings for the old extension.
  • wBlock Advanced/ja.lproj/Localizable.strings
    • Removed Japanese localization strings for the old extension.
  • wBlock Advanced/ko.lproj/Localizable.strings
    • Removed Korean localization strings for the old extension.
  • wBlock Advanced/pl.lproj/Localizable.strings
    • Removed Polish localization strings for the old extension.
  • wBlock Advanced/pt-BR.lproj/Localizable.strings
    • Removed Brazilian Portuguese localization strings for the old extension.
  • wBlock Advanced/ro.lproj/Localizable.strings
    • Removed Romanian localization strings for the old extension.
  • wBlock Advanced/ru.lproj/Localizable.strings
    • Removed Russian localization strings for the old extension.
  • wBlock Advanced/zh-Hans.lproj/Localizable.strings
    • Removed Simplified Chinese localization strings for the old extension.
  • wBlock Advanced/zh-Hant.lproj/Localizable.strings
    • Removed Traditional Chinese localization strings for the old extension.
  • wBlock Scripts (iOS)/Resources/manifest.json
    • Added 'tabs' and 'declarativeNetRequest' permissions to the manifest.
    • Included declarativeNetRequest rules to strip CSP headers for YouTube domains.
  • wBlock Scripts (iOS)/Resources/pages/popup/popup.css
    • Increased the minimum width of the popup body to 340px.
  • wBlock Scripts (iOS)/Resources/pages/popup/popup.html
    • Removed the 'Refresh' button from the element zapper section.
  • wBlock Scripts (iOS)/Resources/pages/popup/popup.js
    • Removed the 'zapperRefresh' variable and its associated event listener.
    • Added a call to reload the active tab after clearing zapper rules.
  • wBlock Scripts (iOS)/Resources/rules/csp_strip_rules.json
    • Added a new JSON file defining declarativeNetRequest rules to remove Content-Security-Policy headers for youtube.com and m.youtube.com.
  • wBlock Scripts/Info.plist
    • Added a new Info.plist file for the macOS Safari Web Extension, configuring its display name, extension point, principal class, and associated content blockers.
  • wBlock Scripts/SafariWebExtensionHandler.swift
    • Added a new Swift file for the Safari Web Extension handler, delegating request handling to WebExtensionRequestHandler.
  • wBlock Scripts/wBlock Scripts.entitlements
    • Renamed the entitlements file from 'wBlock Advanced/wBlock_Advanced.entitlements' to 'wBlock Scripts/wBlock Scripts.entitlements'.
    • Removed the 'com.apple.security.app-sandbox' entitlement.
  • wBlock.xcodeproj/project.pbxproj
    • Updated the project file to remove references to the old 'wBlock Advanced' target.
    • Added a new 'wBlock Scripts' target for the macOS Safari Web Extension.
    • Modified build phases, file references, and target dependencies to reflect the new extension structure.
    • Updated the 'LastSwiftUpdateCheck' version.
  • wBlock/FilterListUpdater.swift
    • Refactored the checkForUpdates method to pre-fetch validators on the MainActor before entering a task group, preventing deadlocks.
    • Introduced PendingValidatorUpdates actor to collect and defer validator writes until after concurrent tasks complete.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@0xCUB3
Copy link
Copy Markdown
Owner Author

0xCUB3 commented Mar 17, 2026

This also fixes #144 (wBlock Advanced not working in web apps/PWAs). Safari App Extensions couldn't run in PWAs, but Web Extensions can.

One tradeoff: the toolbar badge showing blocked element count is gone. That was tied to SFSafariExtensionHandler.contentBlocker(withIdentifier:blockedResourcesWith:) which is App Extension-only. It was never reliable anyway since it only counted network-level blocks, not scriptlet or CSS-based blocks. The popup and element zapper still work as before.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a significant and well-executed refactoring that successfully unifies the macOS and iOS web extensions, which will greatly improve maintainability by reducing code duplication. The fix for the MainActor deadlock in checkForUpdates is particularly noteworthy, demonstrating a solid understanding of Swift concurrency by pre-fetching and deferring MainActor-bound operations. The UI and functionality improvements to the popup are also positive changes. I have one suggestion to enhance error logging to prevent silent failures.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 137fd60b7d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@0xCUB3 0xCUB3 merged commit 7bc44aa into main Mar 17, 2026
2 checks passed
@0xCUB3 0xCUB3 deleted the web-extension-migration branch March 17, 2026 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] YouTube Ads still popping up after new update.

1 participant