Increase timeout on waiting for the injected script to be loaded (I just had it take >1 second). Add 100ms delay before disconnecting the port to avoid occasional exception being thrown due to last message ('done') being in flight.