question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Facebook Ad Content Evades Aggressive Mode

See original GitHub issue

Description

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:

image

Items in the feed:

image

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

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:open
  • Created 2 years ago
  • Reactions:1
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
ryanbrcommented, May 15, 2021

Even with uBO, I’m still seeing ads in Facebook, It doesn’t seem they’re filtering facebook ads currently @antonok-edm

1reaction
jonathansampsoncommented, Nov 19, 2021

@illtellyoulater My prototype is relatively quite dated, so I’m not surprised it was failing at this point 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sensational Content | Transparency Center - Facebook
Advertisers can't run ads that include shocking, sensational or excessively violent content. People have different sensitivities to graphic and violent ...
Read more >
New Facebook Content Moderation Can Affect Your Marketing ...
Facebook content moderation will enforce a new AI system that can potentially block your marketing campaigns. Find out how to prevent that in...
Read more >
About Meta's Sensational Content advertising policy - Facebook
We don't allow shocking, sensational or excessively violent content in ads, including the use of shocking or scary tactics to grab people's attention....
Read more >
Top Facebook Updates You Can't Miss (November 2022 ...
Open beta test of Augmented Reality (AR) ads launching. These ads will be available in both the feed and Stories. Users will be...
Read more >
The best ad blockers in 2022 - Tom's Guide
YouTube has gotten more aggressive with ads, so the makers of ad-blocking extensions have followed suit. Adblocker for YouTube is a Chrome ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found