Skip to content

Conversation

@hyeonjongyang
Copy link
Contributor

Safari 26 adds if-frame-url / unless-frame-url triggers. This PR uses a hybrid approach to support domain.* and domain-regex values while keeping the fast path (if-domain/unless-domain) for plain domains to avoid unnecessary compilation overhead (addresses #100).

Changes:

  • For Safari 26+:
    • Keep using if-domain / unless-domain for plain domains.
    • Use if-frame-url / unless-frame-url only for:
      • TLD wildcards like example.*
      • Domain regexes like /test\\.(com|net)/
    • If a rule contains both plain + special domains, split it into multiple entries (one per trigger type) with the same action/other trigger fields.
  • Update domain list parsing so | inside /.../ domain regex doesn’t split the domain list.
  • Preserve older-Safari third-party workaround behavior.
  • Add unit tests and a changelog entry.

Copy link

@windsurf-bot windsurf-bot bot left a comment

Choose a reason for hiding this comment

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

Other comments (2)

💡 To request another review, post a new comment with "/windsurf-review".

Copy link
Member

@ameshkov ameshkov left a comment

Choose a reason for hiding this comment

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

After merging the previous pull request there are some conflicts to resolve.

In addition, there are some changes that needs to be done for any PR like that. For guidance please see the merge commit with changes that was made to your previous pull request: def0b10

Here's what needs to be done:

  1. README should be updated with the new information on compatibility
  2. Please run make lint to make sure that the code is formatted correctly.
  3. Please update the relevant bench tests with your baseline before and after the change.
  4. FilterEngine and FilterRule at this point don't need to support TLD/regexes, but we'll need a separate issue for this.

@hyeonjongyang
Copy link
Contributor Author

Resolved merge conflicts by rebasing onto master (PR is now MERGEABLE/CLEAN).

Addressed review threads (1–11) and the review summary:

  • Domain regex parsing in Rule.addDomains: fixed empty regex guard + proper closing / detection with escaped backslashes (ead3b80, b35ba29).
  • Safari 26+ domain wildcard/regex support: implemented if-frame-url/unless-frame-url generation + split triggers for plain vs special domains (0cc18bd).
  • Refactors/cleanup requested:
    • Removed stale throws and unnecessary comment; extracted helper functions; added docs (0cc18bd).
    • Switched regex-domain detection to SimpleRegex.isRegexPattern and simplified wildcard domain mapping (plain.map { "*" + $0 }) (c87f678).
  • Correctness/safety for frame-url patterns:
    • Unescape escaped /, $, ,, | inside $domain=/regexp/ and validate final patterns via SafariRegex.isSupported (c87f678).
    • Simplified TLD wildcard escaping (replace . with \\.) (c87f678).
  • README + benchmark baselines updated per review summary (1d76f93).

Lint/test notes:

  • swift test passes locally.
  • swift format lint --recursive --strict . passes.
  • JS/Markdown lint run via local-cache overrides (corepack/pnpm/npm cache issues prevented running make lint exactly as-is in this environment).

Commit list (top):
53a66ff cac30de 9b1f785 1d76f93 4a62f1a c87f678 b35ba29 ead3b80 0cc18bd

Copy link
Member

@ameshkov ameshkov left a comment

Choose a reason for hiding this comment

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

Thank you!

Sorry that the review takes so long, this is due to New Year vacation.

Overall, looks good to me, there are just a couple of things to address.

/// - Swift: 6.2
/// - Average execution time: ~0.787 sec
///
/// Baseline results (Dec 25, 2025):
Copy link
Member

Choose a reason for hiding this comment

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

Could you please check performance before the change and tell me what's the difference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was ~0.892s before, so it’s about a +3.5% increase.

Move $domain=/regexp/ unescaping into SimpleRegex.unescapeDomainRegex and add unit tests.
Split frame-url domain pattern building into helpers, remove continue-based control flow, and document legacy Safari behavior.
@hyeonjongyang
Copy link
Contributor Author

Thank you!

Sorry that the review takes so long, this is due to New Year vacation.

Overall, looks good to me, there are just a couple of things to address.

Thanks for the review, and no worries about the timing.

@hyeonjongyang hyeonjongyang requested a review from ameshkov January 6, 2026 13:51
@hyeonjongyang
Copy link
Contributor Author

Forgot to run the lint 😅

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.

2 participants