That sounds like a great idea! Be careful which foam you get, as previously mentioned!
I used some of that can foam maybe 30 years ago to fix a hollow bdrm door after my tenant punched a hole in it. Came back the next day to finish the patch and the door looked like a giant pillow. And I didn't use that much foam.
Do a test of the foam you buy to test expansion.
I've fixed soft and spongy tub and shower floors using Durhams Rock Hard Water Putty. But I've always removed the shower pan to do it because the stuff mixes like mortar. Shooting foam from a can is an excellent idea in a tight spot if you get the right volume.
Everything written by this author is not claimed to be fact nor fiction and may be considered seriously altered depending on the libation being consumed at time of writ.
2012 FR Stealth 2714 Toyhauler.
2017 Ford F 250, 4x4, Super Cab, 8' bed, 6.2 gas motor.
Various Desert Toys including a Rzr XP Turbo.