x
Main Site login Signup

Load webpage completely in applicaton background

I'm trying to load a webpage in my application background. following code shows How I am loading a page:

             request = (HttpWebRequest)WebRequest.Create("http://example.com");
             request.CookieContainer = cookieContainer;

             using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
             {
                 Stream st = response.GetResponseStream();
                 StreamReader sr = new StreamReader(st);
                 string responseString = sr.ReadToEnd();
                 sr.Close();
                 st.Close();
             }  

as you know, the server responses HTML codes or some javascript codes, but there are many codes which added to the webpage by javascripts functions. so I have to interpret or compile the first HTTP response.
I tried to use System.Windows.Forms.WebBrowser object to load the webpage completely, but this is a weak engine to do this.
so I tried to use CEFSharp (Chromium embedded Browser), it's great and works fine but I have trouble with that. following is how I use CEFSharp to load a webpage:

 ChromiumWebBrowser MainBrowser = new ChromiumWebBrowser("http://Example/");  
 MainBrowser.FrameLoadEnd+=MainBrowser.FrameLoadEnd;
 panel1.Controls.Add(MainBrowser);
 MainBrowser.LoadHtml(responseString,"http://example.com");

it works fine when I use this code in Form1.cs and when I add MainBrowser to a panel. but I want to use it in another class, actually ChromiumWebBrowser is part of another custom object and the custom object works in background. also it would possible 10 or 20 custom objects work in a same time. in this situation ChromiumWebBrowser doesn't work any more!

second problem is the threading issue, when I call this function MainBrowser.LoadHtml(responseString,"http://example.com"); it doesn't return any results, so I have to pause the code execution by using Semaphore and wait for the result at this event: MainBrowser.FrameLoadEnd

so I wish my code be some thing like this:

 request = (HttpWebRequest)WebRequest.Create("http://example.com");
             request.CookieContainer = cookieContainer;
             string responseString="";
             using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
             {
                 Stream st = response.GetResponseStream();
                 StreamReader sr = new StreamReader(st);
                 responseString = sr.ReadToEnd();
                 sr.Close();
                 st.Close();
             } 
             string FullPageContent = SomeBrowserEngine.LoadHtml(responseString);
             //Do stuffs

  

Can you please show me how to do this? do you know any other web browser engines that work like what I want?
please tell me if I'm doing any things wrong with CEFSharp or other concepts.
Someone told me Awesomium can help me, now I don't know is it possible to do or not, can you please help me?

asked Jul 23, 2016 at 08:54 AM avatar image mostafakhaki 0
more ▼
(comments are locked)
10|1100 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.