You can initialize your own macro editor instead using javascript.
AJS.MacroBrowser.setMacroJsOverride('macroName', {
"opener": function () {
}
})
The lifecycle of a custom UI element can be managed here. You may want to leverage Dialog2 component to make this easier: Dialog2 - AUI Documentation
A good community example is here: Custom macro dialog in confluence in editor context | Override MacroBrowser - #3 by aragot