I've used a similar pattern to this with notifications. fireStartupMessages of pushMessaging and fireStartupEvents of notifications are going to be combined into a general solution, so maybe it's best to wait until that happens and then clean up the sendJavascript in both pushMessaging and notifications afterwards.