The Virginia legislature passed bills Tuesday that would make it harder to pursue frivolous lawsuits designed to chill free speech, a response to a string of splashy defamation cases filed in state courts by Rep. Devin Nunes (R-Calif.), actor Johnny Depp and others.

Free speech advocates cheered the legislation in the House and Senate, saying the state’s weak anti-defamation law has made Virginia a magnet for dubious litigation aimed at punishing critics and blunting aggressive media coverage on topics of public concern.

Nunes, Depp and other litigants have filed defamation cases seeking nearly $1 billion in damages in courts in Virginia over the past year. Their targets include CNN, the New York Times, Twitter, the actress Amber Heard, the Fresno Bee and a parody Twitter account in the voice of an imaginary cow.

Nunes and Depp both claim they have been wrongly smeared and say they have good reasons to pursue litigation in Virginia. But defendants and critics say the suits are without merit and the venues were chosen to take advantage of Virginia law.

They say the state does not have an effective mechanism for getting frivolous defamation suits dismissed quickly, meaning someone with deep pockets can harass a defendant with expensive and protracted litigation. Such cases are known as strategic lawsuits against public participation, or SLAPP.

Virginia’s new anti-SLAPP bills would afford defendants stronger protections. Provisions in the House and Senate bills would allow defendants to file a special motion to dismiss a lawsuit after it has been served, if the defendant believes the goal of the lawsuit is to stifle free speech on a topic of civic interest.

The move would pause discovery in cases, which is expensive and time-consuming, and trigger a hearing before a judge. If the defendant prevails on the motion to dismiss, the defendant would automatically be awarded attorneys’ fees under the House bill or could be awarded them in the Senate version.

Del. Schuyler T. VanValkenburg (D-Henrico) said he sponsored the House bill because as a civics teacher, he was concerned about First Amendment rights being thwarted through litigation.

“Shutting down speech, I found that offensive,” VanValkenburg said. “Suing someone and getting them into court kind of cuts against everything I stand for.”

In March, Nunes filed a $250 million defamation suit in Henrico County, accusing Twitter of censoring him and allowing users — including one parody account in the voice of an imaginary cow — to defame him.

“Devin’s boots are full of manure,” read one of the offending tweets by the cow account cited in the lawsuit. “He’s udder-ly worthless and its pasture time to move him to prison.”

Other defamation suits followed against the Fresno Bee, CNN and others over reporting in stories and online commentary about the pieces.

Nunes and his attorney did not respond to requests for comment.

In April, Depp sued Heard, his ex-wife, in a $50 million defamation case in Fairfax County. Depp claimed the actress falsely implied he had abused her in an op-ed in The Washington Post about domestic abuse.

“Johnny Depp brought his defamation case in Virginia because Virginia is where that Washington Post was printed, Virginia is where the online version of that Washington Post was created, and Virginia is where the servers that routed that Washington Post to the rest of the world are located,” Adam Waldman, an attorney for the actor, wrote in a statement.

While the bills are broadly similar, they differ on key details. The House and Senate measures will move to the opposite chamber for consideration and the hammering out of any differences before possibly heading to the governor for signing.

Alison Friedman, of the Protect the Protest task force that is backing the bills, said she is guardedly optimistic about passage.

“Substantively, all the parts for a strong anti-SLAPP bill are there, but half are in the House bill and half are in the Senate bill so it’s really going to come down to conference,” Friedman said.