views:

309

answers:

0

Hi, im using http://smallsharptools.com/Downloads/SmallSharpTools.WebPreview/ in a web application where WebPreview creates thumbnails of given URL.

It works fine as long as there is no javascript prompt on the page. If there is it never finishes loading and timeouts. I assume Webbrowser object it creates waits for user input.

I know Webbrowser control not for a web app but i couldn't find any other tool to get screenshot of a webpage. Anyways, I am looking for a solution wherei either disable javascript on Webbrowser control or a generic timeout where i cans et a timeout limit when calling the method.

Here is the method that gets thumbnail

public class PreviewBuilder
{
  //....snip....
   private Bitmap GetPreviewImage()
    {
        WebBrowser wb = new WebBrowser();
        wb.ScrollBarsEnabled = false;
        wb.Size = new Size(Width, Height);
        wb.ScriptErrorsSuppressed = true;
        wb.NewWindow += new System.ComponentModel.CancelEventHandler(wb_NewWindow);
        wb.Navigate(_url);
        //disable javascript

        // wait for it to load
        while (wb.ReadyState != WebBrowserReadyState.Complete)
        {
            Application.DoEvents();
        }
        Bitmap bitmap = new Bitmap(Width, Height);
        Rectangle rect = new Rectangle(0, 0, Width, Height);
        wb.DrawToBitmap(bitmap, rect);
        return bitmap;
    }

}

and this is how i call it

     PreviewBuilder pb = new PreviewBuilder(url, sourceFilename);
        pb.CreatePreview();