Step 1: Piston cap alternative
Step 2: Trying the end cap
Step 3: Trying the foam
This type of foam starts curing when exposed to the moisture in the air, so the outer layer hardens quickly, but the parts that are buried take a lot longer. When I tried it out I got a couple good shots, then water was able to make it down past the cured foam to the part that was still uncured. The uncured foam worked its way out and fouled up everything resulting in a total loss. Sigh...
This clearly didn't work out like I expected. The idea still has merit, but I'd use a two-part expanding foam if I did it again, so that the cure is not dependent on exposure to air. On the other hand it works okay without the foam, so try it that way first.