So I have been watching videos in facebook. One of my problem was their ads keeps popping out. Also the ads that is showing are products I don’t need and I don’t like it. Hoping for Brave Browser to block this ads.
1 Like
Yeah, this is a work in progress. Since the ads share the same elements as regular comments and posts.
opened 07:40PM - 14 May 21 UTC
OS/Desktop
feature/shields/adblock
uBO-parity
## Description
Facebook displays "Sponsored" items on the main feed and in t… he 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:
![image](https://user-images.githubusercontent.com/815158/118320034-45f05c00-b4c1-11eb-8eae-cc5b7a4d97e4.png)
Items in the feed:
![image](https://user-images.githubusercontent.com/815158/118320096-5c96b300-b4c1-11eb-99a0-b2a76f2d94ef.png)
## 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.
![sponsored-2](https://user-images.githubusercontent.com/815158/118320339-b7c8a580-b4c1-11eb-8dfe-be6ac8b5236c.PNG)
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.
```js
// 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 );
});
```
1 Like
system
Closed
August 2, 2021, 1:13pm
3
This topic was automatically closed after 30 days. New replies are no longer allowed.