Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(privacy): Add debug view to iOS to display blocked requests per-tab #26987

Merged
merged 3 commits into from
Dec 12, 2024

Conversation

StephenHeaps
Copy link
Collaborator

  • Add a BraveIOSDebugAdblock feature flag (default: disabled) that when enabled will display blocked requests for a given tab in it's Shield panel under advanced controls.
    • The flag name is intentionally generic as it will later be used to incorporate more adblock / content filtering debugging tools in the future.
  • These requests are already logged to the console (viewable via Safari debugger when connected to macOS), but now will display in-app

Resolves brave/brave-browser#42842

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

  1. Enter brave://flags and enable #ios-debug-adblock feature flag
  2. Restart the app for feature flag to take effect
  3. Visit any website, tap Shields icon and open advanced controls
  4. Tap Blocked Requests
  5. Verify blocked requests are displayed
  6. Pull down to display search bar, verify filtering works (filters by request url, source url, resource type
Shields Panel (expanded) Blocked Requests Blocked Requests (filtered)

@StephenHeaps StephenHeaps added CI/skip-android Do not run CI builds for Android CI/skip-macos-x64 Do not run CI builds for macOS x64 CI/skip-windows-x64 Do not run CI builds for Windows x64 CI/skip-macos-arm64 Do not run CI builds for macOS arm64 labels Dec 11, 2024
@StephenHeaps StephenHeaps self-assigned this Dec 11, 2024
@StephenHeaps StephenHeaps requested review from a team as code owners December 11, 2024 21:27
@StephenHeaps StephenHeaps force-pushed the privacy/ios-blocked-requests-view branch from d1cc491 to 16efa5a Compare December 11, 2024 21:28
@StephenHeaps StephenHeaps removed the request for review from a team December 11, 2024 21:29

extension Strings.Shields {
public static let blockedRequestsTitle = NSLocalizedString(
"blockedRequestsTitle",
Copy link
Collaborator

Choose a reason for hiding this comment

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

You may want to prefix these strings with Shields (e.g. Shields.blockedRequestTitle) for possible (though unlikely 😅) collision prevention

.searchable(text: $filterText)
}

@ViewBuilder private func row(title: String, detail: String) -> some View {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can drop @ViewBuilder since the computed value is wrapped in Group

sourceURL: document.location.href,
sourceURL: $.windowOrigin,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this intended?

Copy link
Collaborator Author

@StephenHeaps StephenHeaps Dec 11, 2024

Choose a reason for hiding this comment

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

Yeah this was missed in the local frames fix, just for our tracking protection stats. But this debug view feature piggy-backs on that script to catch requests blocked by the content blocker (as opposed to blocked by our request blocking scripts). Some additional info w/ examples.

stats


private var blockedRequests: [BlockedRequestInfo] {
let blockedRequests = Array(contentBlockerHelper.blockedRequests)
guard !filterText.isEmpty else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

if filterText.isEmpty would be easier to parse

@@ -27,13 +27,15 @@ struct ShieldsPanelView: View {
}

private let url: URL
private weak var tab: Tab?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably doesn't need to be weak since this is a View and ShieldsSettingsViewModel is already holding onto the Tab strongly

@StephenHeaps StephenHeaps merged commit 3d49115 into master Dec 12, 2024
18 checks passed
@StephenHeaps StephenHeaps deleted the privacy/ios-blocked-requests-view branch December 12, 2024 20:25
@github-actions github-actions bot added this to the 1.75.x - Nightly milestone Dec 12, 2024
@brave-builds
Copy link
Collaborator

Released in v1.75.97

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/skip-android Do not run CI builds for Android CI/skip-macos-arm64 Do not run CI builds for macOS arm64 CI/skip-macos-x64 Do not run CI builds for macOS x64 CI/skip-windows-x64 Do not run CI builds for Windows x64
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add debug view to display blocked requests on iOS
5 participants