Lawmakers in Washington are pushing for an outright ban of TikTok on American soil. Montana might beat them to it.

The state’s Legislature is further along than any other body in the United States to passing a ban of the popular Chinese-owned video app, which has faced scrutiny for whether it is handing sensitive data about Americans to Beijing. A Montana bill to block the app was introduced in February, and the State Senate approved it last month. It is expected to face a vote in the State House as soon as this week and has a strong chance of passing.

Along the way, the proposal has encountered obstacles. A major internet provider said it could not block TikTok in Montana, prompting lawmakers to rewrite the legislation. A trade group funded by Apple and Google, which operate the app stores that would be forbidden to carry the app, also declared that it was impossible for the companies to prevent access to TikTok in a single state.

And the lobbying has been intense. Critics of China have appeared at hearings supporting the bill. To strike back, TikTok has pushed its users to oppose the legislation by calling and emailing Montana’s Republican governor, Greg Gianforte. A spokeswoman for Mr. Gianforte said he would “carefully consider any bill the Legislature sends to his desk” and noted that he had already banned TikTok on state devices.

The fight in Montana is a preview of what the United States might confront at a national level if lawmakers or the White House tries to enact a nationwide ban of TikTok. Even if legislation disallowing the app is passed, carrying out a ban is technologically difficult and would involve companies across the digital economy.

TikTok could foment a backlash among its 150 million U.S. users. And any ban is likely to face legal challenges, with courts shooting down an attempt by President Donald J. Trump to block TikTok in 2020.

Montana’s attorney general, Austin Knudsen, whose office drafted the bill, acknowledged that enacting a state TikTok ban would be difficult.

“We’re under no illusions that this is not going to get challenged,” he said in an interview. “I think this is the next frontier in First Amendment jurisprudence that’s probably going to have to come from the U.S. Supreme Court. And I think that’s probably where this is headed.”

The proposed ban would take effect in 2024.

The moves in Montana are part of a intensifying technological cold war between the United States and China, with TikTok, which is owned by the Chinese company ByteDance, caught in the middle.

Last month, members of Congress grilled Shou Chew, TikTok’s chief executive, for roughly five hours about whether the app could provide data to the Chinese government or be used to spread propaganda. In the last five years, U.S. officials have also cut off Chinese telecom companies from major suppliers, subsidized stateside manufacturers to compete with Asian chip makers and forced a Chinese company to sell the dating app Grindr.

Brooke Oberwetter, a spokeswoman for TikTok, said in a statement that there were “thousands of TikTok creators and users in Montana” who “deserve to have a seat at the table in any conversation that impacts them and their livelihoods.” TikTok has denied giving user data to the Chinese government.

Mr. Knudsen, a Republican, said his team had received scores of complaints from parents about TikTok content referring to drugs, suicide or pornography. As the state’s legislative session approached this year, his office began looking at the idea of fully banning the app.

The political environment is friendly to a ban. Montanans are already protective of their personal privacy, state politicians said. Then, in early February, a Chinese spy balloon passed over the state, drawing national attention and heightening concerns about Beijing’s espionage.

“Frankly, the Chinese did us a favor by floating that spy balloon over Montana when they did,” Mr. Knudsen said. After his office wrote the bill, State Senator Shelley Vance, a Republican, introduced it on Feb. 20.

The first version of the proposal, which included fines for internet service providers and app stores if they helped to distribute the app, as well as TikTok if it continued to operate in the state, drew little attention when the State Senate’s Business, Labor and Economic Affairs Committee considered it on Feb. 27.

At one point in that hearing, a lobbyist for AT&T stood up and announced that the company opposed the bill. He said it was “not workable” for internet service providers to put a TikTok ban into effect. He said AT&T was discussing a change with the bill’s sponsors that would allow the company to withdraw its opposition to the measure.

Lawmakers had removed any mention of internet providers like AT&T when the State Senate passed the legislation a week later.

By March, TikTok had hired two lobbyists in the state and was running ads featuring Montana small businesses that used TikTok. The app also started to mobilize its users.

“We need your help to stop the Montana State Legislature from taking away your right to use TikTok,” the company said in an email posted to one user’s feed. The company gave users a prewritten email they could send to Mr. Gianforte opposing the bill. It sent a similar warning to users through a notification inside its mobile app, according to another post on TikTok.

The State House’s Judiciary Committee considered the bill, which still required Apple and Google to remove TikTok from their stores, at a March 28 hearing.

App stores frequently take down products. A ban on TikTok could also stop the stores from distributing updates to the app, slowly hobbling the service for users who had already downloaded it. But at the hearing, a representative from TechNet, a trade group whose members include Apple and Google, said it would be “impossible” to restrict TikTok state by state.

Apple and Google declined to comment.

State Representative Zooey Zephyr, a Democrat, said in an interview that it was possible that TikTok users could disguise their location to maintain access to the app even after a ban, which could also be hard to enforce in border towns where internet connections may involve cellular towers in another state.

But skepticism of TikTok ran deep at the hearing. Keith Krach, a former corporate executive behind some of the Trump administration’s efforts to marginalize Chinese companies, testified that he wouldn’t let his 11-year-old twins near the app. He said it was “disguised as candy, but it’s really cocaine.”

“Would you agree with me that TikTok is the music played by the Pied Piper to steal this generation’s heart and mind?” asked Representative Neil Duram, a Republican, as Ms. Zephyr, seated next to him, burst out laughing.

“I’m unsure, a little bit, of what you’re getting at,” replied Keegan Medrano, the policy director for the Montana chapter of the American Civil Liberties Union, which opposes the bill. A post of their exchange quickly gained 70,000 likes on TikTok. Mr. Duram followed up by asking Mr. Medrano if he would agree that “this generation” was, through TikTok, choosing the Chinese Communist Party “as their new god.”

Mr. Medrano said in an interview that the bill could have an impact on speech, possibly making it more difficult for people to discuss topics like “alternative views on vaccines” or “revolutionary moments in other countries.”

Mr. Knudsen said that the bill was about “an enemy superpower nation collecting personal information from Montanans” and that he was prepared for a legal fight.

“I think these are all questions that probably need the courts to step in here,” he said. “We didn’t just crack off this legislation willy-nilly without any thought to that.”

The post A Plan to Ban TikTok in Montana Is a Preview for the Rest of the Country appeared first on New York Times.