Locate a gap or hole in the window header's perimeter. Hold the spray foam can so the nozzle is flush with the gap or hole.
Compress the can's trigger to spray foam into the area. Move the nozzle across the crack or hole while filling it with foam. Avoid overfilling the hole or gap; a little bit of foam goes a long way because it expands as it dries.
Apply caulk around the frame of the window header. Use a caulking gun to apply the caulk. Place the nozzle of the caulk against the seam and slowly disperse the caulk from the tube. Smooth the moist caulk using your fingers or a putty knife so it blends into the window's exterior.