The goalkeeper has endured a difficult season with the Hammers, having been dropped by David Moyes following several below-par performances, but made the starting XI against his former club.
Hart was struggling to see properly as the sun was directly in his eyes as he looked down the New Meadow pitch.
A West Ham fan noticed the on-loan stopper's struggles and decided to throw his cap towards Hart, who in turn gave a thumbs up and put the hat on his head.
The 30-year-old went on to keep a clean sheet in the first half and, before going back into the changing rooms at the break, returned the headgear to its rightful owner.
Hart repeated the feat after the restart as Shrewsbury claimed a goalless draw and a replay at the London Stadium.