In the past I've purchased the odd can of expanding foam of the type with a aerosol plunger and the long plastic straw dispenser and found it to be a right PITA to use.
This time, again with only a small area to plug, I went for a "professional" all metal gun and a gun grade can of foam. What a difference - it was almost a joy to use. The amount of foam dispensed can be adjusted and after a few test squirts on a scrap piece of board filling the void was relatively easy.
It's another tool, albeit only for intermittent use, that I wish that I had purchased a long time ago.
Possibly the only downside is that I also had to purchase a can of foam cleaner which has both an aerosol plunger and also screws on to the gun. The foam has to be cleaned out before it cures.