There was the trip to Germany in July 2017, when the mayor joined protest events around the Group of 20 meeting in Hamburg. The trip’s timing — a day after the ambush killing of a city police officer in the Bronx — brought him heavy criticism.

In February, de Blasio had to cancel a trip to New Hampshire, an early primary state, when a New York Police Department detective was killed in the line of duty.

And in 2015, de Blasio was just returning from a trip to the Vatican when the city reversed itself on a highly watched decision to place a cap on the number of for-hire vehicles. The move was seen by some as a cave-in to Uber, which had launched an aggressive campaign targeting the mayor.

With the mayor still in transit, Anthony Shorris, then de Blasio’s first deputy mayor, was quoted in news accounts about the incident.

De Blasio, who on Thursday announced his entry in the 2020 presidential race, is hardly the first mayor in New York with his sights trained outside the city. John V. Lindsay, like de Blasio, sought the Democratic nomination for president.

Michael R. Bloomberg was known for taking regular jaunts to his estate in Bermuda, including one trip that backfired when a particularly bad snowstorm hit New York. Bloomberg had to fly his private plane back to the city.

For any major public official, leaving town always carries the risk that something eventful might happen during the absence. Now, as de Blasio runs for president, that risk is about to be magnified — along with the question of who is in charge while the mayor is away.

Who runs the show?

According to the City Charter, the mayor can designate a deputy mayor to officially be in charge when he is out of town.

“There’s a hierarchy. It’s first deputy mayor, of course, first, and then it goes through other deputy mayors,” de Blasio said in a recent interview. “There’s usually a stipulated order and the chief of staff as well. So, there’s always one of the deputy mayors in charge.”

Dean Fuleihan is de Blasio’s first deputy mayor. When the mayor is out of town, Fuleihan is assigned his own security detail and becomes the de facto mayor. If there is an incident that called for the mayor to show up to in person, Fuleihan would go.

Fuleihan, whom the de Blasio administration declined to make available for an interview, also consults with de Blasio’s chief of staff, Emma Wolfe, but city officials insisted that de Blasio essentially remained in charge.

“He is on his phone and email, regularly connecting with deputy mayors and commissioners, ensuring the work of the administration continues,” Freddi Goldstein, de Blasio’s press secretary, said of the mayor.

But when de Blasio took a family vacation to Italy in 2014 that was almost 10 days long, his ability to keep tabs on the city was questioned by one of his predecessors, former Mayor Rudy Giuliani.

“It isn’t true that you can run the city from far away,” Giuliani said.

In the role of acting mayor, Jumaane D. Williams?

When de Blasio went to Italy with his family, his vacation spanned parts of 10 days. But the mayor’s staff pointed out that de Blasio would be out of the city just shy of nine days.

Why does that matter? According to the City Charter, if a mayor is absent or unable to perform his duties for nine consecutive days, the public advocate assumes the duties of mayor.

In 2014, Letitia James, then the public advocate, had lawyers on her staff research the executive powers she would have while de Blasio was away.

The current public advocate, Jumaane D. Williams, has said he’s not interested in running for mayor in 2021, when de Blasio’s second and last term expires, but he remains ready to fill in if necessary.

“I ran to be public advocate because that’s the job I want,” Williams said in a statement. “As I said on the campaign trail, I’m ready to fulfill the charter mandate if and when necessary.”

How does a Bronx cheer sound in Iowa?

Lindsay was campaigning in Miami Beach in 1972 when a plane flew overhead with a banner that read: “LINDSAY SPELLS TSOURIS,” using a Yiddish word for trouble.

The banner, purchased by Robert B. Blaikie, a well-known gadfly who was unhappy with the mayor, was a visible example of how New York-style disgruntlement can follow an unfavorite son.

Sid Davidoff, who was Lindsay's deputy campaign manager and is a supporter of de Blasio’s, said Lindsay chose to focus on Florida because there were a lot of former New Yorkers there who knew him. The banner, he said, was a reminder that “you also had people who were in Florida because they didn't like Lindsay.”

“You can talk about your accomplishments, but you also take your negatives on the road,” Davidoff added.

As de Blasio visited ABC’s “Good Morning America” on Thursday to discuss his presidential campaign launch, labor unions and other protesters waited outside, holding signs criticizing de Blasio on everything from labor practices to his housing policies.

“When you are the mayor of New York City you bring media celebrity, but also those who don’t like you,” said Bruce Gyory, an adjunct professor of political science at the University at Albany. “New Yorkers don’t tend to be quiet or shy, and they can play to the New York media and the national media.”

In December 2017, de Blasio got an early taste of what may lie ahead. He traveled to Iowa to speak at a Democratic fundraiser, shortly after acknowledging his intention to create a federal political action committee that he has since used for his travels. A gaggle of police officers, sent by their union, was there to greet him, waving signs in protest.

What you say, even abroad, may be used against you

Former Mayor Edward I. Koch was visiting Ireland in 1988 when a call came in from New York.

Koch had told reporters that he didn’t see British troops in Ireland as an “occupying force.” Even then, in the days before the internet and social media, the news still spread rapidly across the Atlantic.

“The Irish there and here went crazy,” said George Arzt, Koch’s press secretary, who immediately began sending surrogates out to speak with members of the city’s Irish community, and arranging meetings for Koch upon his return.

The episode, Artz said, illustrated the perils of what can happen when the mayor of the largest city in the country leaves town.

“Don’t think you are immune to trouble in the city from being out of the city,” Arzt said.

This article originally appeared in The New York Times.