A lot of research has been done that shows A) affairs happen in happy marriages too (the 'bad marriage' part is often only 'realized' when a guilty spouse begins rewriting their marital history to justify their cheating) and B) most affairs do not begin with someone going looking for an affair partner but by 'just friends' intentions at the beginning, allowing them to weaken one boundary after another until they have crossed a line.
That is why there is so much cheating that happens with a coworker or ex or someone who is in close proximity in which you might not have your guard up, and could possibly rationalize your behavior to yourself until the point where you are emotionally invested in a relationship you did not intend to have (but have done nothing to stop, ignoring all the little red flags along the way, because you were 'just friends.') Obviously this does not happen to everyone. But it DOES happen, probably more than we know.
First your high school ex emails you, tells you she is married with kids so that is ok, she's not fishing, you tell her you're married to, you catch up, trade jokes and family stories, then a couple months later she is telling you her marriage is unhappy, you say, hey my wife really aggravated me last night, you commiserate because it's easy to show the perfect face online, talk about how idyllic things were in high school, trade secrets about how you always wondered if they were the 'one who got away,' then next thing you know you're meeting for coffee, the thrill is still there, you start to think ok, this is cheating but you are unwilling to give up the adrenalin rush this secret between you gives you, even though you know it is wrong, and besides, you haven't slept together, it's not like that. You're 'just friends.' Until you are not.
No one was looking with intent for an affair when they friended this person, or started the project with them, etc. It was curiosity, what might have been boredom, a bad day, whatever.
I think it can be a mistake to think it absolutely can't happen to you, that your spouse who has always been totally against cheating and outspoken about it (BT, DT) will never betray you. It happens all the time, it is happening to someone you know right now, and no one thinks it can happen to them until it does.
Having a happy marriage is not a complete defense against the scenario above. Having strong personal boundaries and coping skills is a better one. Cheating is more about the issues within an individual than the marriage itself.
Facebook does not cause this to happen but it definitely facilitate it.