brave / brave-browser

Brave browser for Android, iOS, Linux, macOS, Windows.
https://brave.com
Mozilla Public License 2.0
17.82k stars 2.33k forks source link

A native menu and a native inject for adblock content picker #40821

Closed atuchin-m closed 1 month ago

atuchin-m commented 2 months ago

Description

The epic: https://github.com/brave/brave-browser/issues/39610 The previous task: https://github.com/brave/brave-browser/issues/40696

Currently content picker typescript doesn't need Brave extension to work, but it's still injected via the background page. We need:

  1. a native inject mechanism
  2. a native menu instead of an extension-based
  3. another impl of API to add a user-defined rule.

No changes in the feature logic are expected.

atuchin-m commented 1 month ago

@rebron To fix https://github.com/brave/brave-browser/issues/39610 we need to reimplement the adblock-related items in the menu, that is done in the PR https://github.com/brave/brave-core/pull/25411.

Here is some product-related questions to answer. Could you please take a look?

before after
image image
rebron commented 1 month ago

@rebron To fix #39610 we need to reimplement the adblock-related items in the menu, that is done in the PR brave/brave-core#25411.

Here is some product-related questions to answer. Could you please take a look?

  • Do we want to rename the menu items or the current state is ok?

I'm wondering if we just bring in Block element up to the menu and we can remove Manage custom filters here. wdyt @ShivanKaul @antonok-edm There's probably still a better name for this. Content blocking if we're keeping the sub-menu.

  • Do we still need to have Leo icon? We don't use it for other items.

It's fine to remove the Brave logo, especially if we do the above.

  • Where the menu Brave should be located? Before the PR we use the extension section, but it's not an extension-related anymore. The the PR I add the item after Print.

Put it back to under Translate to English. Your current location may have Cast... as a menu item. And Create QR Code for this page has Send to your Devices if Sync is enabled.

  • Should we disable or hide the menu when Allows all trackers and ads is set in Shields? Currently we always show it, but added filters will not work if Shields are down.

Always show. It's fine even with allow all tracker and ads to have this option.

  • Should we hide the items in some menu mode (the text selected, the image, the link)? Before the PR we don't care, always show.

That makes sense to me. Don't show when selecting text and on a link. I think with an image, users may want to block that image.

rebron commented 1 month ago
  • Should we disable or hide the menu when Allows all trackers and ads is set in Shields? Currently we always show it, but added filters will not work if Shields are down.

Always show. It's fine even with allow all tracker and ads to have this option.

Actually @ShivanKaul @antonok-edm. I guess with Shields down, blocking elements doesn't work then probably doesn't make sense to have this menu item available as an option.

atuchin-m commented 1 month ago

Actually @ShivanKaul @antonok-edm. I guess with Shields down, blocking elements doesn't work then probably doesn't make sense to have this menu item available as an option.

It's an issue now: if Shields are done, you can still select an item to block and it will be immediately blocked (not by adblock, but by injecting a CSS by the script). But after you reload the page the element will be still visible.

atuchin-m commented 1 month ago
option 1 option 2
image image
Image menu position(before) Image menu position(option 1)
image image
atuchin-m commented 1 month ago

BTW, @rebron WDYT about replacing Block element to Block elements? The first sounds like:

  1. you have to target to particular element, but it works in another way;
  2. you can select only one element. In fact, a new rule often covers multiple items.
rebron commented 1 month ago

Sounds good. Can change it to Block elements for now.

ShivanKaul commented 1 month ago

This is fantastic work @atuchin-m! https://github.com/brave/brave-browser/issues/40821#issuecomment-2328467130 are all very pertinent questions.

I'll chat with @antonok-edm about the context menu label/behaviour (whether under Brave > or top-level) and get back to you by EOD.

Where the menu Brave should be located? Before the PR we use the extension section, but it's not an extension-related anymore. The the PR I add the item after Print.

No strong feelings here, but it might make more sense for it to be right above Inspect, since the next step, creating the filter by selecting it on the page, is in the same category of user actions as Inspecting an HTML element IMO.

Should we disable or hide the menu when Allows all trackers and ads is set in Shields? Currently we always show it, but added filters will not work if Shields are down.

You're right about the behaviour in https://github.com/brave/brave-browser/issues/40821#issuecomment-2330746626, it's definitely a bit confusing. It SGTM to just have it not appear if Ads & Tracker setting is Disabled (or allowed like you said). Shields down would override that setting too.

Should we hide the items in some menu mode (the text selected, the image, the link)? Before the PR we don't care, always show.

I see that a link is actually selectable/blockable currently. I propose hiding the item when text selected (where it doesn't show up, you can only block the div/para), but not in the other 2 situations.

ShivanKaul commented 1 month ago

Okay, here's a suggestion:

  1. Move the Block elements to be top-level. Get rid of the Manage custom filters.
  2. Add a Manage custom filters button alongside Create and Quit after the user selects an element. image
atuchin-m commented 1 month ago

@rebron @ShivanKaul PTAL: imageimage

  1. I've moved the menu in before the extension section (aka under Translate to ..);
  2. The new button Manage filters is added. BTW, these button are not translatable now (the same for Create and Quit)
  3. The menu item is visible iff:
    • the page url is http or https; i.e. it's hidden on brave://settings or on NTP.
    • no text is selected;
    • the selected element isn't link (no href);
    • if it's image we show the item despite the previous rule;
    • Shields isn't in Allows all trackers and ads state;
ShivanKaul commented 1 month ago

Thanks @atuchin-m.

  1. Looking at the screenshots, I do think it would be better for Block elements to live in the View Page Source and Inspect section. If it's not too much trouble, let's make this change.
  2. Just want to clarify the "text selection" behaviour: if I select text, and then right-click on the text, the text stays selected. I agree that it doesn't make sense to have the menu item be visible then. However, if I select text, and right-click somewhere else on the page, the text selection goes away. In this latter case, we do want the menu item to be visible. I'm pretty sure this is what you're saying, but wanted to double-check.
  3. We do want links/hrefs to be blockable.

Everything else SGTM.

atuchin-m commented 1 month ago

@ShivanKaul thanks for the comment.

  1. it looks harder to implement because there is no fixed anchor. Inspect could be invisible.
  2. yep, we do show the menu item if the selection goes away in the click moment. The condition is about the opposite to Leo AI tool, you could try it yourself.
  3. The current PR hides the item for text links (if it's not an image). We could change it to show it for all the links. Just to clarify that the content picker doesn't preselect the hovered element. It's a page level action like inspect: after clicking it a user have to select the element again.
ShivanKaul commented 1 month ago

Gotcha, that all seems fine then. I guess I can't think of a case where a user might want to block an item on the page that was a hyperlink but not an image, so we can leave it out for now.

atuchin-m commented 1 month ago
@ShivanKaul @rebron Ok, let's move the item, it isn't a rocket science. Also it is always shown for links. blank space click link click
image image
petemill commented 1 month ago

IMO it should still have the Brave shields icon in the menu, but if that's been decided otherwise then fine.

ShivanKaul commented 1 month ago

Your rationale is that it's a Brave Shields feature? I considered that, just seems slightly inconsistent to have a Brave logo (which happens to be the same as the Shields logo) for this but not Leo context menu or Copy Clean Link.

atuchin-m commented 1 month ago

For QA: it makes sense to verify all the related changes together: https://github.com/brave/brave-core/pull/25330 https://github.com/brave/brave-core/pull/25358 https://github.com/brave/brave-core/pull/25411

Scenario 1:

  1. Launch the browser, open any site (i.g reddit.com)
  2. Right click on blank space and click Block elements
  3. Click on the item, content picker mode should be activated.
  4. Select a item and click Create.
  5. Verify that the item is blocked immediately
  6. Reload the page, verify the item is blocked
  7. For any controversial behavior check v1.69.x (Brave => Block element) as the reference

Scenario 2 (Manage filters):

  1. Select Block elements
  2. Select any element, click Create
  3. Click Block elements again, click Manage filters button.
  4. Verify the shields settings are opened and there is a new rule related to the domain you test (i.e. reddit.com)

Case 3 (Menu position and show/hide logic). Verify that:

  1. Block elements item is always above Inspect
  2. the item is shown for any link we right-clicked and isn't shown for selected text.
  3. the item is hidden when Shields are down
  4. the item is hidden on NTP or brave://settings
LaurenWags commented 1 month ago

Adding QA/Blocked pending response from https://github.com/brave/brave-browser/issues/40696#issuecomment-2362112901

kjozwiak commented 1 month ago

The above requires 1.71.95 or higher for 1.71.x verification 👍

issuant commented 1 month ago

@atuchin-m @kjozwiak Will this be coming to Android? #33241

MadhaviSeelam commented 1 month ago

Verification PASSED using

Brave | 1.71.109 Chromium: 129.0.6668.89 (Official Build) beta (64-bit)
-- | --
Revision | 538f203fb4c3449f0684dbabd4ef6e777c4e4a3b
OS | Windows 11 Version 23H2 (Build 22631.4249)

Testcase 1: (Create)

  1. Installed 1.71.109
  2. launched the browser (relaunched to pull griffin)
  3. visited nytimes.com
  4. opened context menu in a blank space and clicked Block elements option
  5. confirmed clicking Block elements activated the content picker mode
  6. clicked on selected element and rules-box is activated
  7. clicked Create in the rules-box
  8. confirmed the element is blocked immediately
  9. opened brave://settings/shields/filters page
  10. confirmed the rule is written to the create custom filters box
  11. Reloaded the page
  12. confirmed the item is still blocked
  13. opened brave://settings/shields/filters page again
  14. confirmed rule is still shown
  15. removed the rule and clicked save button
  16. reloaded nytimes.com tab
  17. confirmed blocked element reloaded
step 4 step 5 step 7 step 8 step 10 step 12 step 15 step 17
Image Image Image Image Image Image Image Image Image

Testcase 2 (Manage filters):

  1. continued from testcase 1 -visited nytimes.com
  2. opened context menu in a blank space and clicked Block elements option
  3. clicked on selected element and rules-box is activated
  4. clicked create in the rules box
  5. verified the selected element is blocked
  6. confirmed clicking Create in the rules-box writes the rule into brave://settings/shields/filters without any issues
  7. repeated step 4-5
  8. clicked Manage filters button in the rules box
  9. confirmed brave://settings/shields/filters page is opened and there is a new rule related to the domain you test (i.e. nytimes.com)
step 3 step 4 step 7 step 9
Image Image Image Image

Testcase 3 (Menu position and show/hide logic).

  1. continued from testcase 2
  2. visited https://en.wikipedia.org/wiki/Main_Page in a new tab
  3. confirmed Block elements item is always above Inspect via context menu
  4. confirmed Block elements is being displayed via the context menu for links
  5. confirmed Block elements is not being displayed for selected text in the context menu
  6. confirmed Block elements is hidden on NTP
  7. confirmed Block elements is hidden for brave://pages
  8. confirmed Block elements is not being displayed when Allow all trackers & ads in a page
  9. confirmed Block elements is being displayed when Block trackers & ads & Aggressive is selected
step 3 step 4 step 5 step 6 step 7a step 7b
Image Image Image Image Image Image
step 8a step 8 b step 9a step 9b
Image Image Image Image
LaurenWags commented 3 weeks ago

Verified with

Brave | 1.71.105 Chromium: 129.0.6668.89 (Official Build) beta (x86_64)
-- | --
Revision | f69ba167992437799f1dbcce81e90ba501a3d63e
OS | macOS Version 14.7 (Build 23H124)

Verified test plan from https://github.com/brave/brave-browser/issues/40821#issuecomment-2352446992.

Case 1 - PASSED 1. Launch the browser, open any site (i.g reddit.com) 2. Right click on blank space and click `Block elements` ![Image](https://github.com/user-attachments/assets/7c4771c4-837e-423c-bf8d-a75cbce2a511) 3. Click on the item, content picker mode should be activated. ![Image](https://github.com/user-attachments/assets/164101b6-998f-4c2f-9817-55bbde81b397) 4. Select a item and click `Create`. ![Image](https://github.com/user-attachments/assets/3077ded3-d18d-4424-b7ed-f62376899951) 5. Verify that the item is blocked immediately ![Image](https://github.com/user-attachments/assets/ea857def-dd4a-4e05-940c-159c6b35257d) 6. Reload the page, verify the item is blocked
Case 2 (Manage filters) - PASSED 1. Select `Block elements` 2. Select any element, click `Create` ![Image](https://github.com/user-attachments/assets/2b57e3f9-fd24-4f4b-afa6-3980c497367d) | ![Image](https://github.com/user-attachments/assets/04ee2d2c-cc13-4a3e-9615-fd8a588e582d) --- | --- 3. Click `Block elements` again, click `Manage filters` button. 4. Verify the shields settings are opened and there is a new rule **related to the domain you test** (i.e. brave.com) ![Image](https://github.com/user-attachments/assets/f5033ebd-1d43-406e-a925-77ec6f0f55c9) 5. Confirmed if I remove the rule and select `Save changes` that when I go back to the page and reload, the element is shown again. ![Image](https://github.com/user-attachments/assets/6d3a4bd0-dea4-4124-902e-c66118ccdaad) | ![Image](https://github.com/user-attachments/assets/e3345c4b-3b9d-47e6-acd5-828240db99ee) --- | ---
Case 3 (Menu position and show/hide logic) - PASSED 1. `Block elements` item is always above `Inspect` Clicked on a few different areas of brave.com to get different context menus to confirm that "Block elements" is above "Inspect" Right click on blank space | Right click on an image | Right click on a button --- | --- | --- ![Image](https://github.com/user-attachments/assets/6f063a3f-53e2-46d5-8663-a007bc4c32ae) | ![Image](https://github.com/user-attachments/assets/c951a0af-9bdc-4fe0-aea8-609b8c704b63) | ![Image](https://github.com/user-attachments/assets/4ab4b517-b20f-426c-a566-41121a815bad) 2. the item is shown for any link we right-clicked and isn't shown for selected text. Link | Text --- | --- ![Image](https://github.com/user-attachments/assets/5260d876-3714-4524-8a2f-95141a1e993b) | ![Image](https://github.com/user-attachments/assets/b647dbbc-6151-4593-b1cb-87e802e267ed) 3. the item is hidden when Shields are down Note, per discussion via https://bravesoftware.slack.com/archives/C7VLGSR55/p1728502567294939?thread_ts=1728501796.503369&cid=C7VLGSR55, this is how this feature is working: - "Block Elements" visible when shields completely disabled - "Block Elements" not visible when shields set as "Allow all trackers & ads" - "Block Elements" visible when shields set as "Aggressively block trackers & ads" or "Block trackers & ads" Shields down | Aggressively block trackers & ads | Block trackers & ads | Allow all trackers & ads --- | --- | --- | --- ![Image](https://github.com/user-attachments/assets/c6353fbb-b48c-4f3f-80c4-27741279693d) | ![Image](https://github.com/user-attachments/assets/64447b3e-3bb4-45d4-828f-c4eb3c57a8c3) | ![Image](https://github.com/user-attachments/assets/c0219079-07f9-4a45-9fdf-ecbf212d1964) | ![Image](https://github.com/user-attachments/assets/a6f93806-4690-4910-92b2-12d7d788fc26) 4. the item is hidden on NTP or brave://settings Confirmed no "Block elements" on NTP or brave://settings Example | Example | Example --- | --- | --- ![Image](https://github.com/user-attachments/assets/f31953a0-a535-4ae0-8759-1380168dc58c) | ![Image](https://github.com/user-attachments/assets/20bce757-5600-4784-9379-c89a3fcd5f1c) | ![Image](https://github.com/user-attachments/assets/8775cf4c-3a16-4119-be13-f2b87b3384fa)
LaurenWags commented 2 weeks ago

Verified with

Brave | 1.71.112 Chromium: 130.0.6723.44 (Official Build) (64-bit)
-- | --
Revision | 7d51df656b247f9432ee714a6d160142a1e11c13
OS | Linux

Verified test plan from https://github.com/brave/brave-browser/issues/40821#issuecomment-2352446992.

Case 1 - PASSED 1. Launch the browser, open any site (i.g reddit.com) 2. Right click on blank space and click `Block elements` ![Image](https://github.com/user-attachments/assets/e36942ef-efba-4844-b125-a1d251c8922e) 3. Click on the item, content picker mode should be activated. ![Image](https://github.com/user-attachments/assets/c5eeead7-8533-451d-8161-a05101609bdb) 4. Select a item and click `Create`. ![Image](https://github.com/user-attachments/assets/4b919b9e-147b-48ce-892f-f3e4cc24fa46) 5. Verify that the item is blocked immediately ![Image](https://github.com/user-attachments/assets/5a1545be-c9b5-4fc0-81d2-6ebc0200b997) 6. Reload the page, verify the item is blocked
Case 2 (Manage filters) - PASSED 1. Select `Block elements` 2. Select any element, click `Create` ![Image](https://github.com/user-attachments/assets/8660e6d5-20c2-44d9-a7f9-93bd43e0ac68) | ![Image](https://github.com/user-attachments/assets/2018bfe6-4bb3-4fd4-8cb5-d94737d62f7a) --- | --- 3. Click `Block elements` again, click `Manage filters` button. 4. Verify the shields settings are opened and there is a new rule **related to the domain you test** (i.e. brianbondy.com) ![Image](https://github.com/user-attachments/assets/17a7742a-3a43-48ce-b130-0261afb61af7) 5. Confirmed if I remove the rule and select `Save changes` that when I go back to the page and reload, the element is shown again. ![Image](https://github.com/user-attachments/assets/1eef9993-4e54-49e8-8642-95cada794f68) | ![Image](https://github.com/user-attachments/assets/c0f5332a-ab73-4d3c-bd28-50c88b6f2ebd) --- | ---
Case 3 (Menu position and show/hide logic) - PASSED 1. `Block elements` item is always above `Inspect` Clicked on a few different areas of brave.com to get different context menus to confirm that "Block elements" is above "Inspect" Right click on blank space | Right click on an image | Right click on a button --- | --- | --- ![Image](https://github.com/user-attachments/assets/f05ea416-49c3-4893-b4e4-54381872fe55) | ![Image](https://github.com/user-attachments/assets/03ce8d02-789d-40ba-9b3c-e01acc2b6132) | ![Image](https://github.com/user-attachments/assets/fdc8d026-8c60-4eb8-b154-b81174b6d824) 2. the item is shown for any link we right-clicked and isn't shown for selected text. Link | Text --- | --- ![Image](https://github.com/user-attachments/assets/6bef4012-1d04-4200-8828-1bc8f47eeb90) | ![Image](https://github.com/user-attachments/assets/3e6d6149-cdb8-4fff-9939-e2a45a461a3f) 3. the item is hidden when Shields are down Note, per discussion via https://bravesoftware.slack.com/archives/C7VLGSR55/p1728502567294939?thread_ts=1728501796.503369&cid=C7VLGSR55, this is how this feature is working: - "Block Elements" visible when shields completely disabled - "Block Elements" not visible when shields set as "Allow all trackers & ads" - "Block Elements" visible when shields set as "Aggressively block trackers & ads" or "Block trackers & ads" Shields down | Aggressively block trackers & ads | Block trackers & ads | Allow all trackers & ads --- | --- | --- | --- ![Image](https://github.com/user-attachments/assets/99383df3-cb0f-4aa5-a37f-ec41e0a27546) | ![Image](https://github.com/user-attachments/assets/157a4c16-3b00-49b7-b4e2-9c88eeda9ae6) | ![Image](https://github.com/user-attachments/assets/abe1ca3d-684c-45e8-a44a-ae1de692f5a5) | ![Image](https://github.com/user-attachments/assets/2396b5f8-85b7-47ae-b31d-bba1dc7e1ef4) 4. the item is hidden on NTP or brave://settings Confirmed no "Block elements" on NTP or brave://settings Example | Example | Example --- | --- | --- ![Image](https://github.com/user-attachments/assets/eca7fece-c001-4e29-93c8-d0629048a089) | ![Image](https://github.com/user-attachments/assets/0d4919d7-dc9f-4629-8305-5b156d677fc1) | ![Image](https://github.com/user-attachments/assets/86ad460e-dfbb-4b15-89cd-ed29b86e3b4e)