Instead of a command, attach a dynamic js behavior to ensure the callback is executed properly after everything else has run.
Ported refactorings and changes from 7.x-1.x.