– Senate Republicans and Democrats credited Facebook and Twitter on Wednesday for efforts they have taken to rid their sites of foreign meddling, in a stark shift from the harsh criticism that they have leveled at the social media companies for months.

In a hearing with the Senate Select Committee on Intelligence, lawmakers said Facebook and Twitter had recognized the problem of foreign influence on their platforms and were engaging more with Congress. The lawmakers agreed with the companies that the responsibility to root out foreign interference on social media would also require government help.

Their comments helped relieve pressure on Sheryl Sandberg, COO of Facebook, and Jack Dorsey, CEO of Twitter, who appeared at the hearing. Both executives came armed with conciliatory messages, acknowledging during the 2.5-hour session that they had been late to discover that foreign operatives had used their sites to spread false and divisive messages. Each outlined steps their companies have taken to root out disinformation and foreign influence campaigns, including new tech tools to identify fake accounts and hiring thousands of content monitors.

"After the election, you were reluctant to admit there was a problem," Sen. Mark Warner, D-Va., vice chairman of the committee, said. "Each of you have come a long way with respect to recognizing the threat."

Facebook, Twitter and Google have faced scrutiny since the 2016 presidential election for how foreign agents used their platforms to influence the American electorate. In previous hearings on the issue over the past year — notably when Mark Zuckerberg, the Facebook CEO, testified in Washington in April — lawmakers have grilled the tech executives and faulted their companies for being unaware of the problems.

But after being pilloried for months, Sandberg and Dorsey learned that simply showing up and engaging more with Congress in recent months has vastly improved relations in Washington. At one point, the Senate Intelligence Committee chairman, Richard Burr, R-N.C., said lawmakers also had a responsibility with the social media companies.

"I think the observation that no one company can fight this on their own is spot on," Burr said. "We need to be candid about responsibility — and by that I mean both the responsibility we have to one another, from one side of this dais to the other, as participants in this public policy discussion."

Not all the tech companies were treated as well. Google, which had declined an invitation to send Larry Page, CEO of parent company Alphabet, to appear alongside the other tech executives prompted ire from lawmakers. An empty chair was placed at the witness table to intentionally draw attention to Google's absence.

"To the invisible witness, good morning to you," said Sen. Kamala Harris, D-Calif.

Several lawmakers were even harsher. Sen. Marco Rubio, R-Fla., said Google may not have shown up "because they are arrogant." He added that Google executives may have wanted to dodge questions over a recent report of a consumer watchdog group posing as a Russian troll farm that tried to buy ads on Google.

Sandberg and Dorsey, both in black suits, had different styles during the hearing. Sandberg, a former chief of staff to the Clinton Treasury Department, was polished and referred to talking points. Dorsey read prepared remarks from his phone, from which he also live-tweeted his remarks.

After the hearing ended, Sandberg and Dorsey quickly left the room without talking to reporters.

Dorsey also appeared Wednesday afternoon in a House Energy and Commerce Committee hearing on the topic of content moderation.

At the House hearing, Energy and Commerce Chairman Greg Walden, R-Ore., cited recent complaints that Twitter limited the visibility of prominent Republicans on its platform — a charge echoed by Trump himself.

"It takes years to build trust, but it only takes 280 characters to lose it," Walden said.

Dorsey strongly denied that political ideology has played a part in any Twitter algorithms that determine what users see.

The assertion that conservatives are being censored has also been pushed by House Majority Leader Kevin McCarthy, R-Calif., and the No. 3 House Republican, Steve Scalise of Louisiana.

Committee Democrats charged that Republicans were manufacturing the issue ahead of the November elections.

"This hearing appears to be one more mechanism to raise money and generate outrage," said Rep. Frank Pallone of New Jersey, the committee's top Democrat.

The Associated Press contributed to this report.