Use pushdown automaton for state changes, fix issue with non ShadowDOM-native browsers