InfoBox window not resizing to fit content

I cant seem to control the height of the infobox on first click. I want the frame to extend to include the whole picture with text.

When I click on the entity for the first time, the infobox crops the content like above, but if I deselect and click on the entity again, it seems to work as intended and resizes to include all the content. I need it to work the first time.

I found this snippet on ChatGPT but I get an error with maxWidth. I had a look in the console and I cant find any attribute for infoBox to do with maxWidth or maxHeight.

 var infoBox = document.getElementsByClassName('cesium-infoBox'); = 'none'; = 'none';