Skip to content

Safari build, macOS/Linux build scripts, Safari fixes, and the Reddit NSFW fix - #55

Open
asimovtekir wants to merge 4 commits into
codepurse:mainfrom
asimovtekir:feat/safari-build
Open

asimovtekir wants to merge 4 commits into
codepurse:mainfrom
asimovtekir:feat/safari-build

Conversation

@asimovtekir

Copy link
Copy Markdown
Contributor

Summary

Builds BlockNSFW 2.0.8 for Safari, adds macOS/Linux build scripts for Chrome and Firefox, and fixes the Safari runtime problems found while testing it. The Reddit NSFW-subreddit fix (6448086, eaefeb8) is also included in this PR.

Safari build

  • build-safari.sh stages the Firefox build into dist/safari/extension/ (Safari has no chrome.offscreen, and the Firefox build already runs the image classifier on the background page). It then generates the Xcode project with safari-web-extension-converter, and with --build signs the app ad hoc so it runs locally. The script doesn't package for the App Store; that needs a developer team and a real bundle ID.

Safari runtime fixes

  • Dynamic rules: if Safari can't take one rule in an updateDynamicRules batch (its content-blocker regex has no alternation or \d, which rules out the Bing rule), it refuses the whole batch. That left 0 SafeSearch, whitelist and custom-image rules. A refused batch now falls back to adding rules one at a time. Refusals are remembered per extension version and browser build, an update that would change nothing makes no call, and updates run one at a time. Browsers that accept the batch keep the single atomic swap.
  • Startup: ready (and so onboarding) no longer waits on the dynamic-rules update or the blocklist cache write. Safari recompiles every rule list on each accepted call (16–28 s before ready), and can leave a large storage.local.set unsettled forever.
  • Site access: Safari stores "Always allow on every website" as *://*/* and answers false for <all_urls>, so either pattern now counts as access. Chrome and Firefox behave as before.

Chrome/Firefox builds on macOS and Linux

  • build-chrome.sh / build-firefox.sh (via scripts/build-extension.sh) take the same flags as the .ps1 builds: --zip, --open-source, --sandbox. They also make the same checks: store mode, committed tree, Supporter extras, build timestamp, AI assets, and a read-back of the zip by check-package.js. The file lists are read from the .ps1 scripts, so the platforms can't drift apart.
  • Chrome's _metadata/ is gitignored. README documents the new scripts.

Reddit (included)

  • NSFW subreddits were opening unblocked for signed-out visitors. Reddit now answers about.json with a 403 for every subreddit, and the 403 was read as "not NSFW". The flag is now read from the <reddit-page-data> Reddit serves (prefixedName), and an unknown answer never blocks and is never cached. A refused about.json request (a 403/429, or a NetworkError in Firefox) pauses those requests for 10 minutes. <shreddit-post nsfw> posts are hidden in feeds.

Testing

  • npm test: 1438/1438 pass.
  • ./build-chrome.sh --zip --open-source and ./build-firefox.sh --zip --open-source: both packages pass check-package.js (133 and 131 files).
  • ./build-safari.sh --build --open-source: the app builds and is signed ad hoc. The staged extension has exactly the Firefox build's file list. A clean first run in Safari opens onboarding.
  • All three builds are 2.0.8 and include the Safari and Reddit changes.
  • Not run: web-ext lint (not installed locally), and a store build (extras-private not available here).

🤖 Generated with Claude Code

asimovtekir and others added 4 commits November 19, 2026 17:41
NSFW subreddits opened unblocked for signed-out visitors. The check asked
/r/<name>/about.json; Reddit now answers that with an HTML 403 ("You've
been blocked by network security") for every subreddit, SFW or not, and
the 403 was read as "not NSFW". Its HTML pages are served after a JS
challenge; its JSON endpoints are refused outright.

- readRedditPageNsfw(): the answer from <reddit-page-data> (subreddit.isNsfw),
  trusted only when it names the subreddit asked about (directly or via
  <shreddit-screenview-data> with the same id), so data left behind by an
  in-app navigation is not borrowed. No request is made.
- checkRedditSubredditNSFW() returns null, not false, when Reddit has not
  answered (403/429, network error, no over18). Unknown never blocks and is
  never cached. A 403/429 pauses about.json for 10 minutes: Reddit refuses
  the client, not one subreddit, and a feed would otherwise send a refused
  request per post.
- recheckRedditPage(): processContent's check runs at document_start, before
  the page data parses, and skips while a pass is running. Asked again on
  DOMContentLoaded and whenever a <reddit-page-data> is added.
- SOCIAL_SELECTORS.reddit matches <shreddit-post>, and its `nsfw` attribute
  hides the post. The old selectors matched no element on current Reddit.

Tests: tests/reddit-nsfw.test.js (14).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…equest

Found running the built extension in Firefox 158:

- Reddit's <reddit-page-data> names the subreddit as `prefixedName`
  ("r/pics"), not `name`. The redirect worked only because
  <shreddit-screenview-data> happened to be on the page too.
- Firefox's content script gets Reddit's about.json refusal as a
  NetworkError, not a 403 (on main as well). The catch returned null but
  did not pause, so with <shreddit-post> now matched, every post linking a
  subreddit would send a failing request and print a console error. It now
  pauses like a 403, and logs only in debug mode.

Tests: tests/reddit-nsfw.test.js (16).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… wait on storage

- Dynamic rules: Safari refuses a whole updateDynamicRules batch over one
  rule its content-blocker regex can't take (Bing's alternation), which left
  0 SafeSearch, whitelist and custom-image rules. A refused batch now falls
  back to one rule at a time, remembers the refusals per version and browser,
  and skips calls that would change nothing. Updates run one at a time.
- Startup no longer awaits the dynamic-rules update or the blocklist cache
  write. Safari recompiles every rule list per accepted call (16-28 s before
  ready) and can leave a large storage.local.set unsettled forever.
- Site access: Safari stores "Always allow on every website" as *://*/* and
  answers false for <all_urls>, so either pattern now counts as access.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- build-chrome.sh / build-firefox.sh run scripts/build-extension.sh: the
  same steps and checks as the .ps1 builds (store-mode and committed-tree
  checks, extras, timestamp, asset checks, zip read back by
  check-package.js), with the file lists read from the .ps1 scripts so the
  platforms can't drift.
- build-safari.sh stages the Firefox build through it into
  dist/safari/extension/, generates the Xcode project with
  safari-web-extension-converter and, with --build, signs the app ad hoc to
  run locally.
- Chrome's _metadata/ (written when the repository root is loaded unpacked)
  is ignored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codepurse codepurse closed this Nov 19, 2026
@codepurse codepurse reopened this Nov 19, 2026
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.

3 participants