Add "onBeforeClose" callback