Help - Correct way to interact with lightbox via javascript?

I am trying to figure out the correct way to interact with the lightbox using javascript. I have seen this [How-to] Create a Click-Thru + Scroll Convertable and some other threads suggesting to use window.postMessage but haven’t had any luck getting it to work.

On the window.ub object, there is a lightbox property, but it only contains and openLightbox function.

I want to attach an event listener to a button and close the lightbox when the event is triggered. I appreciate any help, thanks.