Added this script to my GitHub repository. It extends the capabilities of the @lukaskollmer script and provides support for editing existing code header comments in scripts. Suggestions and improvements are always welcome.
sorry, one more question. if the problem is your main loop, you could kill your main loop's activity before launching the webbrowser; i.e check for a flag at the start if each loop, and make sure you delay long enough that the loop is done, or use a Semaphore, etc.