from Hacker News

Show HN: Simple script to cripple personalized targeting from Facebook

by GeoHubToday on 6/22/24, 9:38 PM with 119 comments

  • by bqmjjx0kac on 6/22/24, 10:38 PM

    This got a little stuck on a few of the `.click()` calls for me. Here's my version:

        const wait = () => new Promise(resolve => setTimeout(resolve, 1000));
        const getElementsByAriaLabel = (label) => document.querySelectorAll(`[aria-label="${label}"]`);
        const getElementsByRoleAndWidth = (role, width) =>
            Array.from(document.querySelectorAll(`[role="${role}"]`)).filter(el => el.clientWidth === width);
        const getElementsByText = (text) => Array.from(document.querySelectorAll('*')).filter(el =>
            Array.from(el.childNodes).some(node => node.nodeType === Node.TEXT_NODE && node.textContent.includes(text))
        );
    
        async function clickAndWait(elem) {
            if (!elem)
                return;
            elem.click();
            await wait();
        }
    
        await clickAndWait(getElementsByText("See more")[0]);
    
        const ads = getElementsByRoleAndWidth('listitem', 508);
    
        for (const ad of ads) {
            console.log(ad.childNodes[0].textContent)
            await clickAndWait(ad.childNodes[0]);
    
            await clickAndWait(getElementsByText('They uploaded or used a list to reach you.')[0]);
    
            const dont_allow_btns = getElementsByText('Don\'t allow');
            for (const btn of dont_allow_btns) {
                btn.click();
            }
            await wait();
    
            await clickAndWait(getElementsByAriaLabel('Back')[2]);
            await clickAndWait(getElementsByAriaLabel('Back')[2]);
        }
  • by junto on 6/22/24, 9:56 PM

    Cool script.

    My hack is to live in a country where the local language is not my own, and not the one I have set in my Facebook settings.

    As a result, Facebook rarely has advertisements that can target me, because my language has been filtered out by the advertisers.

    When one does appear, it’s nearly always in the local language, so I’m kind of deaf to it and I’m not going to actively respond to anyway.

    Luckily they haven’t figured that out yet, even though I’ve been an Facebook user for many years.

  • by tgsovlerkhgsel on 6/23/24, 12:23 AM

    Much more entertaining: Get the list of advertisers. Find the ones who aren't allowed to share your data with Facebook, e.g. due to lack of consent or because they're bound by professional secrecy (e.g. banks or health related things). Report to your local DPA.
  • by Terr_ on 6/22/24, 9:56 PM

    Reminds me of a court case [0] proactively challenging Facebook, due to a time the company gave someone a lifetime ban [1] for making this kind of consumer-tool.

    [0] https://www.theregister.com/2024/05/02/meta_facebook_tool/

    [1] https://slate.com/technology/2021/10/facebook-unfollow-every...

  • by EvgeniyZh on 6/23/24, 5:38 AM

    Reminder to use AdNauseum [1] that will not only hide the ads but also click it, messing with targeting and spending advertisers' money at the same time.

    [1] https://adnauseam.io/

  • by mgraczyk on 6/22/24, 11:28 PM

    What is the motivation to prefer untargeted ads over targeted ones?
  • by josephcsible on 6/23/24, 1:08 AM

    I'm worried that if you use this, Facebook will permaban you for something like "using modified or unauthorized clients to interact with Facebook services".
  • by SSLy on 6/22/24, 10:20 PM

    Intresting, for me the link 404's

      This page isn't available
      The link may be broken or the Page may have been removed. Check to see if the link that you're trying to open is correct.
      Go to Accounts Centre
    
    
    also

      Uncaught SyntaxError: await is only valid in async functions, async generators and modules
  • by Terr_ on 6/22/24, 10:50 PM

    Separately, Firefox has a feature to isolate Facebook activity from other things you do on the web.
  • by stevage on 6/22/24, 10:59 PM

    Weirdly, as much as I hate internet ads in general, I actually find the FB ones better. I've even bought some stuff from a few and been happy.
  • by atleta on 6/22/24, 11:13 PM

    For me the correct URL seems to be: https://www.facebook.com/adpreferences/ad_settings/?section=... instead of what you have in the gist. (But the script errs on the awaits.)
  • by 29athrowaway on 6/22/24, 11:00 PM

    I heard that sites like Facebook run A/B tests all the time, and the version you get served at a given time may not be the same others see. I also suppose the version you see may be slightly different on different territories somehow.

    Also, these scripts break often as they depend on observable behaviors that are not contracts. It's Hyrum's law again.

  • by rkagerer on 6/22/24, 9:56 PM

    Does this just impact ads shown on the site, or does it also cut down on data collection and targeting that occurs when you browse to third party sites who happen to include javascript from Facebook?

    How's this technique compare to just staying logged out of Facebook? Or using it solely in a sandboxed browsing environment?

  • by throwaway_5753 on 6/23/24, 12:46 AM

    What's the legality of a script like this? Could this be construed as a violation of the CFAA if you were a motivated/evil enough lawyer?

    I recall some surprising legal outcomes in recent years, for example jail for posting fake Yelp reviews. Anyone know of any case law for this sort of scripting?

  • by technion on 6/23/24, 4:24 AM

    The part I'm finding most interesting is that I clicked this link and have never heard of pretty much any of the targeted advertisers listed there.
  • by GeoHubToday on 6/22/24, 11:23 PM

    OP here, I've updated the script for a bit more robust support when dealing with slow/delayed endpoint calls! Thanks for the feedback, HN!
  • by seadan83 on 6/22/24, 11:47 PM

    Awesome script! I'm watching it run now :)

    Question, could someone explain the exact impact this would have for Facebook & a person's experience with ads?

    I kinda have a few guesses, but am curious if anyone can weigh in with more info, how this is crippling and overall what the effect should be. Thanks!

  • by unstatusthequo on 6/22/24, 10:13 PM

    What browser is this intended for? The below error comes up on Brave on MacOS. Both most up to date version.

    VM172:14 Uncaught TypeError: Cannot read properties of undefined (reading 'click') at <anonymous>:14:71 (anonymous) @ VM172:14

  • by rayeng on 6/25/24, 1:19 AM

  • by jeremiemyhren on 6/22/24, 10:23 PM

    I get this on Safari on macOS: SyntaxError: Unexpected identifier 'wait'

    and this on Chrome on macOS: TypeError: Cannot read properties of undefined (reading 'click') at <anonymous>:14:71

  • by bequanna on 6/23/24, 7:19 PM

    This doesn't appear to recognize any existing 'Don't allow' selections and fails when you've already disallowed some advertisers.
  • by smashah on 6/22/24, 10:23 PM

    Godspeed good sir. When those shitheads from PerkinsCoie send you a legal threat make sure to share and shame them for it.
  • by exabrial on 6/23/24, 6:59 PM

    Unbelievable and incredible who hard Facebook makes this to do by hand. Completely unethical
  • by smusamashah on 6/22/24, 11:19 PM

    What are the actual steps using the UI if one chooses to do it manually?
  • by ThinkBeat on 6/22/24, 11:30 PM

    and he is banned from Facebook.

    (for some that is a relief for others it is serious)

  • by exabrial on 6/23/24, 6:45 PM

    Anyone have something like this for Google?
  • by JojoFatsani on 6/23/24, 2:50 AM

    Thank you OP, you're a mensch.