SAN FRANCISCO — Kids. The reckless rants and pictures they post online can often get them in trouble, by compromising their chances of getting into a good college or even landing them in jail. What to do about such lapses vexes parents, school officials, the Internet companies that host their words and images — and the law.

Now California legislators are trying to solve the problem with the first measure in the country to give minors the legal right to scrub away their online indiscretions. The legislation puts the state in the middle of a turbulent debate over how best to protect children and their privacy on the Internet, and whether states should even be trying to tame the Web.

The governor, Jerry Brown, has taken no position on the bill. He has until mid-October to sign it, after which, without his signature, the legislation becomes law.

California is often in the vanguard when it comes to digital privacy. It was the first state to require companies to report data breaches, and it requires Web sites and mobile apps to post privacy policies that explain how personal information is used. A recently passed law requires Web sites to tell users whether they honor browsers’ do-not-track signals.