propublica / facebook-political-ads

Monitoring Facebook Political Ads
MIT License
237 stars 50 forks source link

Facebook posts' context menus spontaneously open (and steal my arrow-key-focus) #87

Closed dholbert closed 5 years ago

dholbert commented 5 years ago

STR:

  1. Be logged in to facebook.
  2. Install Facebook political ad collector
  3. Visit https://www.facebook.com/
  4. Wait ~15 seconds.

ACTUAL RESULTS: After waiting 10-15 seconds, the facebook "context menu" spontaneously opens, from the top right of the topmost post in your feed.

(Annoyingly, this happens even if you were scrolling with the arrow keys -- and the context menu "steals focus" and snaps you back up to to the first post, and the menu becomes the thing that the arrow keys are scrolling. So all of a sudden, you're snapped to a different scroll position and your arrow keys are scrolling through the context menu instead of through your feed.)

I'm hitting this 100% of the time in Firefox release (63) and also Chrome ("dev channel" version 72), on Ubuntu 18.10 linux on a 64-bit Lenovo laptop.

I'm using extension version 1.8.1 in Firefox, and 1.8.0 in Chrome (latest available from their respective addon sites). I was testing in a fresh (created today) Firefox profile and a basically-fresh Chrome profile -- no other extensions.

Note: I tried a hard-refresh based on a suggestion in another issue, but it doesn't help - the issue still happens.

dholbert commented 5 years ago

Here's a screencast of this bug in action (starting with facebook.com loading, and with the context menu spontaneously opening after ~11 seconds): https://www.dropbox.com/s/lqesa5xufom54j4/politico-extension-screencast.ogv?dl=0

I didn't interact with my browser at all during the time before the context menu opens.

jeremybmerrill commented 5 years ago

Hi @dholbert This is very helpful (especially the screencast). I suspect additional hard-refreshes may help; though maybe not, since you're seeing this on multiple browsers (which wouldn't be sharing a cache). In any case, what I believe is happening with this bug is that some FB users get different markup than others...

dholbert commented 5 years ago

Yeah, a hard-refresh does not help, unfortunately (nor does starting with a 100% fresh browser profile, which should be the Ultimate Hard Refresh :) ).

Thanks for chiming in, in any case; let me know if there's anything I can do to help diagnose.

jeremybmerrill commented 5 years ago

I appreciate your willingness to help.... On Monday I could build for you a debug version of the extension that would highlight which bit of the detector code is misbehaving (by changing some text colors). Would you be willing to install that and either take a screenshot or telling me what it looks like?

dholbert commented 5 years ago

Sure, I'd be happy to! Though I might not be able to get to it until Tuesday.

jeremybmerrill commented 5 years ago

@dholbert if you have time and are willing to give it a shot, would you install this debug extension? https://www.dropbox.com/s/m0zba0v7sz0mhpe/debug_extension.zip?dl=0

Easier in Chrome (or in whatever versions of Firefox allow unsigned extensions); for Chrome, you'd unzip it someplace, toggle the developer mode switch on chrome://extensions, then click "Load unpacked" and find the unzipped extension.

What this does is two things:

  1. highlight the things that the ad detector preliminarily considers to maybe be ads, by turnning the text green or pink.
  2. test a new mechanism detecting if a "Sponsored" tag is real (i.e. on an ad) or a red herring (i.e. invisible but present in the markup of non-ad posts, e.g. those from your friends)

What'd be helpful for you to tell me is:

  1. when the context menus open, what color is the text?
  2. with this extension, are the context menus still opening on non-ads? (If there not, and if I can impose on you, can you re-install the production version of the extension to confirm that the bug is still happening with it?)

You're welcome to drop me a line by email about this or continue discussing here. My email is jeremy dot merrill at propublica dot org.

jeremybmerrill commented 5 years ago

PS that debug extension (a) doesn't feed ads into the database (instead looking for one running locaclly) and (b) is built off of the experiment/sponsoredeverywhere branch.

dholbert commented 5 years ago

Thanks! I gave the extension a quick try in a few spare minutes this evening, and my results:

So it seems that something in the debug version of the extension is preventing the context menus from appearing. I'm not sure if that's good or bad. :)

dholbert commented 5 years ago

Happy to try another version or to dig in further with some other steps on current debug version, tomorrow, BTW.

dholbert commented 5 years ago

BTW I'm seeing errors being reported by the debug version, in case that's relevant. Chrome DevEdition 72 shows some special errors in chrome://extensions behind a button labeled "errors" alongside the debug version of the add-on: screenshot from 2018-12-11 07-08-33

And both Firefox Nightly and Chrome DevEdition show some errors in their consoles -- here's a screenshot of some (with a backtrace) in Nightly: screenshot from 2018-12-11 07-12-48

These might just be normal logging or irrelevant, but I'm posting them just in case they're useful (or if they happen to be related to why the issue doesn't reproduce with this debug version of the add-on).

jeremybmerrill commented 5 years ago

@dholbert Thank you very very much for testing this out. I think the reason the issue doesn't reproduce is that I've fixed the problem :).

The overarching problem (I think...) was that Facebook has adjusted the markup of ALL posts (both ads/sponsored posts and your friends' vacation photos) for some users (you, but not me) to include "Sponsored". This confused our ad collector's ad detector, since "Sponsored" was one of the things it looked for; since "Sponsored" was everywhere, the detector continued to the next step, which involves the context menu...

Now we're checking if Sponsored has height and width > 0 (cf. the numbers after checkSponsor in the logs you screenshotted); I believe you've confirmed that this does properly distinguish actual sponsored posts from non-sponsored posts. (Hence the context menus not popping up; we don't need to progress to that detector step for all posts, just actual ads, for which the context menus are handled quickly and don't actually appear.)

The red text on actual sponsored posts is the good result: that means those posts have been properly detected as ads.

And FYI: the errors you're seeing are not "real" errors, just verbose logging.

Thank you again for your help in debugging this. The mainline production version of the extension should launch with this fix in a day or two.

dholbert commented 5 years ago

That's great news! Thanks for fixing this.

Once the update goes out, I'll be happy to retest & post some confirmation of the fix here.

jeremybmerrill commented 5 years ago

@dholbert v1.8.2 should be live (and autoupdating w/i 24hrs) in both Chrome and Firefox. Would love if you'd install it and let me know if you're seeing the menus opening on non-ad posts. (Shouldn't be any text color changes in the "real" non-debug version)

dholbert commented 5 years ago

Yup, looks fixed!

I tested 1.8.1 (previous version, from the "all versions" page), and I verified that I was still seeing the issue there.

Then I installed 1.8.2 from the same page, and I'm no longer seeing the issue. Instead: after 10 seconds, I do see a very brief context menu popup above the first sponsored post, but it disappears right away. (Maybe this part is expected and roughly how it's supposed to work?)

jeremybmerrill commented 5 years ago

@dholbert Phew! I'm very glad to hear it. This was a bug that's been cropping up for months and has been a real journey to try to investigate (only some users, happens sporadically, the issue turned out not to be with ads but with non-ad posts etc.). Thank you very much for your willingness to test this out, it's a huge help.

Yeah, that is expected behavior. No way around it that I'm aware of to get the "Why am I seeing this?" text.

dholbert commented 5 years ago

Hooray, thank you for fixing it!