What are you going to cover the chipboard with then?
I would have carefully filled the gap with foam, as you said, buy a gun and a loose bottle, single-use bottles don't work for small jobs.
Then I would have caulked with a good paintable soft joint sealant, e.g. Tec7.