-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Update cosmetic filtering to be able to override page elements with !important
styles
#20177
Comments
Reported from the community; https://community.brave.com/t/foodnetwork-com-ad-boxes/316301 |
I've confirmed that this works: // New helper function
void HideCssSelectorsInFrame(const blink::WebLocalFrame& frame,
const base::ListValue& selectors) {
std::string stylesheet_text;
for (const auto &selector : selectors.GetList()) {
stylesheet_text.append(
selector.GetString() + " {display:none !important;}\n");
}
frame.GetDocument().InsertStyleSheet(
blink::WebString::FromUTF8(stylesheet_text),
nullptr,
blink::WebDocument::kUserOrigin); // <-- this is the important part
} I'm not sure how to best integrate with the if (force_hide_selectors_list &&
force_hide_selectors_list->GetList().size() != 0) {
std::string json_selectors;
if (!base::JSONWriter::Write(*force_hide_selectors_list, &json_selectors) ||
json_selectors.empty()) {
json_selectors = "[]";
}
// Building a script for stylesheet modifications
std::string new_selectors_script = base::StringPrintf(
kForceHideSelectorsInjectScript, json_selectors.c_str());
web_frame->ExecuteScriptInIsolatedWorld(
isolated_world_id_, blink::WebString::FromUTF8(new_selectors_script),
blink::BackForwardCacheAware::kAllow);
} with base::ListValue* force_hide_selectors_list;
if (resources_dict->GetList("force_hide_selectors",
&force_hide_selectors_list)) {
HideCssSelectorsInFrame(*web_frame, *force_hide_selectors_list);
} Solves the issue. |
Another example, possibly related empty spaces: https://community.brave.com/t/arstechnica-com-blank-ad-boxes/317201 on
|
!important
styles
Verified
|
Brave | 1.37.37 Chromium: 98.0.4758.87 (Official Build) nightly (x86_64) |
---|---|
Revision | e4cd00f135fb4d8edc64c8aa6ecbe7cc79ebb3b2-refs/branch-heads/4758@{#1002} |
OS | macOS Version 12.3 (Build 21E5196i) |
Steps:
- installed
1.37.37
- saved the minimal HTML testcase to my desktop
- started a webserver locally via
python3 -m http.server
- loaded the file over the webserver:
http://localhost:8000/Desktop/issue20177/issue20177-testcase.html
- confirmed issue in
1.35.101
build, in bothaggressive
andstandard
Shields modes - switched back to
1.37.37
Confirmed fix in both aggressive
and standard
Shields modes: no gray box showing.
Confirmed gray box shows when allow all trackers & ads
is set or Shields are Down
/Off
.
webserver | 1.35.101, aggressive | 1.35.101, standard | 1.37.7, aggressive | 1.37.7, standard | 1.377 .7, allow all trackers & ads |
---|---|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Verified PASSED
using
Brave | 1.37.40 Chromium: 98.0.4758.87 (Official Build) nightly (64-bit) |
---|---|
Revision | e4cd00f135fb4d8edc64c8aa6ecbe7cc79ebb3b2-refs/branch-heads/4758@{#1002} |
OS | Linux |
Steps:
- installed
1.37.40
- saved the minimal HTML testcase to my desktop
- started a webserver locally via
python3 -m http.server
- loaded the file over the webserver:
http://localhost:8000/issue20177-testcase.html
- confirmed issue in
1.35.101
build, in bothaggressive
andstandard
Shields modes - switched back to
1.37.40
Confirmed fix in both aggressive
and standard
Shields modes: no gray box showing.
Confirmed gray box shows when allow all trackers & ads
is set or Shields are Down
/Off
.
webserver | 1.37.7, aggressive | 1.37.7, standard | 1.377 .7, allow all trackers & ads |
---|---|---|---|
![]() |
![]() |
![]() |
![]() |
Verified PASSED
using
Brave | 1.37.46 Chromium: 98.0.4758.87 (Official Build) nightly (64-bit) |
---|---|
Revision | e4cd00f135fb4d8edc64c8aa6ecbe7cc79ebb3b2-refs/branch-heads/4758@{#1002} |
OS | Windows 10 Version 21H2 (Build 19044.1526) |
Steps:
- installed
1.37.46
- saved the minimal HTML testcase to my desktop
- started a webserver locally via
python3 -m http.server
- loaded the file over the webserver:
http://localhost:8000/issue20177-testcase.html
- confirmed issue in
1.35.101
build, in bothaggressive
andstandard
Shields modes - switched back to
1.37.46
Confirmed fix in both aggressive
and standard
Shields modes: no gray box showing.
Confirmed gray box shows when allow all trackers & ads
is set or Shields are Down
/Off
.
webserver | 1.37.7, aggressive | 1.37.7, standard | 1.377 .7, allow all trackers & ads |
---|---|---|---|
![]() |
![]() |
![]() |
![]() |
Verified using Beta
Tablet:
|
Originally found on https://www.foodnetwork.com/recipes/food-network-kitchen/classic-shrimp-scampi-8849846, where
#dfp_bigbox_recipe_top
and a few other banner ad spaces are not being collapsed. Corresponding filter rules are present in Easylist as generic class/id cosmetic filters.Minimal example:
The gray box should not be shown with Shields in aggressive mode. uBlock Origin is able to handle this correctly.
Of note is that Brave Shields creates a
constructed stylesheet
rule, which gets overridden by the inlinedisplay: block!important
style on the element. uBlock Origin creates aninjected stylesheet
rule, which has higher precedence.The text was updated successfully, but these errors were encountered: