title: I want to programmatically launch a browser with a URL, wait for it to finish, then close the browser
body: <p>I have created an Html 5 page that provides important server-side functionality.  Unfortunately, it must be run in an Html 5 browser (Chrome, IE9, or Firefox) with a canvas to produce the results I need.  It is completely self contained, taking needed parameters through the URL, and is ready to be closed when the OnLoad event is ready to send.  So far so good.</p>
  
  <p>The following process needs to be automated (no human eyes or interaction) and will be run from within a web service (not run from within a browser).  Ideally, I don't want to waste extra cycles with busy wait, or delay the result by waiting for long time periods simply hoping the process has finished.  I need to:</p>
  
  <ol>
  <li>Open a browser (preferably Chrome) with a URL, using C#. </li>
  <li>Wait for the page to completely finish loading - ideally receiving a callback of some kind.</li>
  <li>Close the browser page when finished, again with C#.</li>
  </ol>
  
  <p>We've tried using IE9.  There is C# support to launch IE9, Wait until not Busy, and gracefully Close the browser; however, the page loads resources asynchronously (there is no way around this), and so we get the signal that it is no longer busy during the resource load - instead of when the page has finished.  Adding busy wait would consume valuable server-side cpu cycles.</p>
  
  <p>A simple Create Process call would be nice, but would only work if the browser could close itself with some html - but thanks to security measures in the browsers, I can't find a reliable way to use html commands to close a browser that was launched from command-line (I did see you can close tabs spawned from an already opened page - firefox only, but this doesn't help).</p>
  
  <p>Does anyone know how I can accomplish this goal?  Again - there is no human involvement in any of the process, no human eyes will ever see the page or interact with it in any way.  The page only runs on the server machine, and will never be deployed to a client machine. </p>