-
Notifications
You must be signed in to change notification settings - Fork 920
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
Collapse HTML elements with blocked image/iframe requests #9144
Conversation
if (error_code == net::ERR_BLOCKED_BY_CLIENT) { | ||
status.should_collapse_initiator = true; | ||
} | ||
OnRequestError(status); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should handle all of these in OnRequestError
7d42ac4
to
bcb592d
Compare
0e61c2d
to
e91bfd4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for chromium_src/
collapse_status.should_collapse_initiator = true; | ||
} | ||
|
||
target_client_->OnComplete(collapse_status); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we please add a test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did look into this briefly - collapsed elements cannot be detected in JS, and the only API Chromium exposes for this is HTMLImageElement::IsCollapsed()
(and similar for iframes), which is pretty deep in Blink.
Is it allowed to access the Blink elements in browsertests? Otherwise we could probably try some hacky JS where we check the size of a parent element, but it seems fragile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried for a bit to access IsCollapsed
, but I don't see any convenient way to do it. I've used the JS clientHeight
property instead, which I've found works here.
c8e2530
to
5419b32
Compare
content::WebContents* contents = | ||
browser()->tab_strip_model()->GetActiveWebContents(); | ||
|
||
ASSERT_EQ(true, EvalJs(contents, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EXPECT_TRUE
@@ -15,6 +15,8 @@ namespace features { | |||
// substituted for any canonical name found. | |||
const base::Feature kBraveAdblockCnameUncloaking{ | |||
"BraveAdblockCnameUncloaking", base::FEATURE_ENABLED_BY_DEFAULT}; | |||
const base::Feature kBraveAdblockCollapseBlockedElements{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please add a comment?
|
||
ASSERT_EQ(true, EvalJs(contents, | ||
"let i = document.getElementsByClassName('adImage');" | ||
"i[0].clientHeight === 0")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs a comment
Resolves brave/brave-browser#14825
Resolves brave/brave-browser#14960
Submitter Checklist:
QA/Yes
orQA/No
;release-notes/include
orrelease-notes/exclude
;OS/...
) to the associated issuenpm run test -- brave_browser_tests
,npm run test -- brave_unit_tests
,npm run lint
,npm run gn_check
,npm run tslint
git rebase master
(if needed)Reviewer Checklist:
gn
After-merge Checklist:
changes has landed on
Test Plan:
Fix for brave/brave-browser#14825
Load the following HTML page from an HTTP or HTTPS source (i.e.
http://
orhttps://
, not afile://
URL):With default Shields settings, only one frame (
example.com
) should be visible. The other two frames should be hidden.With "Allow all trackers & ads" selected in the Shields panel, or with Shields disabled altogether, all three frames should be visible. Contents should load in the second frame (
123freeavatars.com
) and the third frame (example.com
).With default Shields settings, but with
#brave-adblock-collapse-blocked-elements
disabled inbrave://flags
, all three frames should be visible but only the last one (example.com
) should actually load.Fix for brave/brave-browser#14960
Visit https://www.twitch.tv/directory and observe profile and video thumbnail images loading correctly.
Add
||*^$image,domain=twitch.tv
to the "Custom filters" section ofbrave://adblock
and reload the Twitch page.Observe that the profile and video thumbnail images are missing from the page, and that no "broken image" placeholders appear on the page.
Finally, disable
#brave-adblock-collapse-blocked-elements
inbrave://flags
and relaunch the browser. The missing images on the Twitch page should now have visible "broken image" placeholders like below: