The G.O.P. nominee repeated crude insults, and his supporters relished each moment. But the display could alienate swing voters.

Former President Donald J. Trump on Saturday spewed crude and vulgar remarks at a rally in Pennsylvania that included an off-color remark about a famous golfer’s penis size and a coarse insult about Vice President Kamala Harris.

The performance, 17 days before the election in a critical battleground state, added to the impression of the Republican nominee as increasingly unfiltered and undisciplined. It comes as some of Mr. Trump’s allies and aides worry that Mr. Trump’s temperament and crass style are alienating undecided voters.