Facebook Ad Content Evades Aggressive Mode
See original GitHub issueDescription
Facebook displays “Sponsored” items on the main feed and in the side-bar, even when shields are configured to engage in Aggressive blocking.
Steps to Reproduce
Use Facebook, and look at the items in your feed and side-bar 🙂
Actual result:
Items in the top-right:
Items in the feed:
Expected result:
Ads should not be shown when the user has engaged Aggressive blocking.
Reproduces how often:
Easily.
Brave version (brave://version info)
1.24.85
Miscellaneous Information:
The DOM around Sponsored content is designed to confuse queries. For example, the “Sponsored” string is constructed for numerous elements, interspersed with positioned elements throughout.
One approach would be to use a Mutation Observer to identify/excise ads. The following was constructed as a quick proof of concept. A clear limitation here would be the expectation that the string displayed to the user is in English. This is not likely to be the case for most users.
// We expect the feed element to exist before proceeding
document.addEventListener( "DOMContentLoaded", () => {
// Hides a post if it has <span>o</span> or <span>Suggested for You</span>
// Posts have numerous spans, with 'Sponsored' broken up into chars
const removeSponsoredFeedItems = post => {
const nodes = post.querySelectorAll( "span:not([style])" ) || [];
const spans = [ ...nodes ];
spans.some( e =>
e.textContent === "o"||
e.textContent === "Suggested for You"
) && post.remove();
};
// Listens for new post elements in the feed
const observer = new MutationObserver( changes => {
for ( const change of changes )
for ( const node of change.addedNodes )
if ( node.parentElement.matches("[role='feed']") )
removeSponsoredFeedItems( node );
});
const feed = document.querySelector("[role='feed']");
const nodes = feed.querySelectorAll("[data-pagelet^='FeedUnit']");
const config = { childList: true, subtree: true };
// Processes first sponsored element in the page
nodes.forEach( removeSponsoredFeedItems );
// Processes any subsequent sponsored element in the page
observer.observe( document.documentElement, config );
});
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:12 (6 by maintainers)
Even with uBO, I’m still seeing ads in Facebook, It doesn’t seem they’re filtering facebook ads currently @antonok-edm
@illtellyoulater My prototype is relatively quite dated, so I’m not surprised it was failing at this point 🙂