It was Saturday night in Edgartown, and on the town’s sidewalks, behind lines of police tape and stern-looking officers, excited onlookers craned for a better view.

Children were raised aloft onto older shoulders, their faces lighted up by the bluish glow of hundreds of smartphones. The crowd had been gathering for almost two hours and now, as a convoy of black SUVs and gray minivans started their engines, everyone was anticipating action.

“Beyoncé’s coming,” a photographer jokingly called out.

In truth, an arguably bigger celebrity was expected: the president of the United States, with the rest of the first family in tow.

As a Times of London journalist who is on loan to The Post for a few months, I find the extent of the cult of celebrity surrounding the Obamas striking.

Throughout last week, the president looked like a man who, on a rare excursion from the intensity of living in one of the most famous buildings in the world, wanted nothing more than to be left alone for a few days. And yet the crowds and the media were determined to ensure he wasn’t.

This summer scrutiny stands in contrast to the treatment of politicians in Britain. Although the sex lives and private indiscretions of MPs are considered fair game — for both the tabloid and broadsheet press — vacations have remained more sacred territory.

The state’s administrative and ceremonial roles are combined into one office in the United States. By contrast, in Britain, the royal family — who play no part in the daily business of government — do the heavy lifting when it comes to feeding the nation’s appetite for celebrity stories.

Whether the royals are on the ski slopes of Klosters or — notoriously — sunbathing on a private balcony in the south of France, the paparazzi’s lenses remain fixed on William and Kate.

But even then, they are given some space for privacy, thanks in part to something of an unwritten deal between the unruly press and Buckingham Palace.

While living on the island of Anglesey off the northwest coast of Wales, the Duke and Duchess of Cambridge have largely been allowed to go about their lives like any other young couple. Protective residents have helped keep photographers away as Kate shops in a grocery store and William enjoys an occasional drink at a pub.

Here, islanders have repeatedly told me that Martha’s Vineyard prides itself on being unfazed by its regular high-profile guests. But throughout last week, it was clear that, although movie stars, talk-show hosts and comedians might be left undisturbed, many are unable to contain their excitement when POTUS is in town.

Across Martha’s Vineyard, dozens of handmade signs punctuated journeys along major roads, and waving crowds littered the scenery wherever the motorcade went. The messages were often ones of greeting, simple and seemingly heartfelt, and of encouragement for the legislative battles ahead.

“Thank you, Mr. President — keep up the good fight — the Ambulos family,” read one particularly earnest example Sunday. The sign, placed at the end of a single-lane track near the Obamas’ vacation home, was surrounded by a glittery array of American flags.

Farther along on the same brief trip to an island golf course, a woman in a straw hat held up a piece of paper with a hand-drawn heart and the letter “U.”

Others used the president’s visit to lobby him. Among the more unexpected sights along the motorcade’s route was a demonstrator dressed as a polar bear — a display of opposition to the Keystone XL pipeline.

Despite the throngs clamoring for attention, Obama did his best to remain out of view. He held no public events and, besides thanking the occasional well-wisher, only worked a rope line once, while collecting fried seafood Tuesday at Nancy’s in Oak Bluffs.

But even when he was away from the crowds, he was not left alone — thanks to what is, to these eyes, a peculiar U.S. tradition: the protective travel pool.

The American media clearly feel that they have a duty to be on hand at all times, in case developing events — such as violence in Egypt, or other emergencies — intrude. The practical result of this pious goal, though, is that the assembled journalists are left covering events that are really no more than tabloid fodder.

It gives rise to strange situations, such as the sight of almost a dozen fully grown adults waiting, voyeurlike, on the edge of a forest to catch a glimpse of two girls, ages 12 and 15, out for a holiday bike ride with their parents.

Despite trailing the president everywhere, the traveling press pool can go entire days without actually laying eyes on him. Senior correspondents are reduced instead to spending hours sitting in a coach nearby, with the closest thing to news being the disclosure that Larry David, the “Curb Your Enthusiasm” star and Vineyard summer resident, was a member of Obama’s golfing foursome Saturday.

Small wonder then, that Obama opted to spend so much time hitting the links during this trip — a total of 271 / 2 hours over six rounds.

Time on the island’s lush greens and tree-lined fairways is pretty much the closest thing to freedom — or at least a regular vacation — that Obama gets, although he remained ringed by the not-so-discreet Secret Service agents wearing the seemingly obligatory uniform of ill-fitting beige pants.

All the while, a short distance away, the press sits patiently, waiting for the next scrap of news.