Sen. Kamala Harris, D-Calif., has never wavered in her opposition to capital punishment, but she sure has taken plenty of heat over the years from advocates on both sides of the issue. Scrutiny of her approach to the death penalty as San Francisco’s district attorney and California’s attorney general is likely to follow her through each step of her quest for the presidency.

If anything, Gov. Gavin Newsom’s signing of an executive order to halt executions in the nation’s most populous state will only elevate the death penalty in the Democratic primary, where candidates will compete on who is the most adamant opponent, and in a potential general election against President Trump, an unabashed supporter.

Harris immediately tweeted praise for Newsom’s shutdown of a system that is “immoral, discriminatory, ineffective, and proven to be unequally applied.” She then went further by pledging that no one on federal death row — a rogue’s gallery that includes Charleston, S.C., church shooter Dylann Roof and Boston Marathon bomber Dzhokhar Tsarnaev — would be executed on her watch.

No one who has followed her career closely should be surprised.

Harris made a similar pledge in her longshot 2003 campaign for San Francisco district attorney. The death penalty was only an issue to the extent that the more conservative of the three challengers, had flip-flopped from support to opposition in an attempt to make himself more palatable in a liberal city. It didn’t work. He finished third behind Harris and incumbent Terence Hallinan.

It didn’t take long for the murder of 29-year-old police officer Isaac Espinoza to put Harris’ convictions to the test. She did not flinch.

“It was hot,” Harris said of the reaction. “Remember, there had not been a police officer killed in the line of duty in San Francisco in a generation. Democrats weren’t necessarily being vocal about their position on the death penalty in those days.”

Yet some certainly were.

At the young officer’s funeral at St. Mary’s Cathedral, Sen. Dianne Feinstein, D-Calif., called for the killer’s execution — and drew a standing ovation from a crowd with many blue uniforms, as Harris sat in the front row. State Attorney General Bill Lockyer, another Democrat, vowed to take over the case, but later backed down. It took years for Harris to repair relations with the law enforcement community, and some may never forgive her.

“The question I’ve reflected on is whether I should have waited until after his funeral,” Harris said in a phone interview Friday. “Maybe it was a political novice mistake. I don’t know. Maybe it was the right thing to do but you got to take the heat for it.”

David Hill, who shot the officer with an AK-47, was convicted and sentenced to life without parole.

Harris was widely regarded as the underdog in her 2010 statewide race for attorney general largely because of her opposition to the death penalty. Steve Cooley, the Los Angeles district attorney, was an unambiguous supporter, and a July 2010 Field Poll showed that 70 percent of Californians agreed with him on its legality.

“People thought I shouldn’t run because of my position on the death penalty — and certainly believed I couldn’t win,” Harris said.

She won, albeit in a race so close that it took weeks to resolve the outcome.

At that point, it would seem the newly elected attorney general’s bona fides as a capital punishment opponent would be beyond reproach.

Then came a fresh challenge to her convictions. In 2015, a federal district court judge, ruling in the case of a murder-rapist who had been on death row for a quarter century, declared that the delay and uncertainty amounted to “cruel and unusual punishment.” Harris appealed that ruling, much to the frustration of abolitionists. Why, they asked, did she simply agree that the death penalty was unconstitutional, as she did with Proposition 8 (the ban on same-sex marriage), and refused to defend it?

There were two reasons, Harris explained. One, she had no choice from a legal perspective. As attorney general, the Department of Corrections was her client. (In the Prop. 8 case, she would have been operating in an independent capacity on behalf of the initiative’s opponents, and thus had the option to pass). The other was her substantive disagreement with the judge’s argument that capital cases took too long between conviction and execution.

“Justice is something you don’t speed up,” she said. Still, she acknowledged the awkwardness of pushing an appeal that successfully upheld the death penalty — at least until Newsom took office.

“It was one of the most difficult things I had to do,” she said.

Harris also has drawn criticism from the left for failing to take positions on ballot measures that would have repealed the death penalty. Again, she said it came down to her role as an attorney general whose duties including writing the title and summary for state propositions. She wanted to avoid the perception of a potential conflict as both advocate and arbiter of ballot language.

There is no mystery about what Harris did in the privacy of the voting booth.

“I personally voted to repeal the death penalty,” she said.

John Diaz is The Chronicle’s editorial page editor. Email: jdiaz@sfchronicle.com Twitter: @JohnDiazChron