add support for returning promises on onbeforechange