4

I'm trying to make an advanced C# web browser (navigation, favorites, home, history, tabs) without using the WebBrowser control in visual studio. I can't find any tutorials online. Anyone who can help with a tutorial?

I've so far started with

 string urlAddress = "http://google.com";

 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlAddress);
 HttpWebResponse response = (HttpWebResponse)request.GetResponse();

 if (response.StatusCode == HttpStatusCode.OK)
{
   Stream receiveStream = response.GetResponseStream();
   StreamReader readStream = null;

   if (response.CharacterSet == null)
  {
      readStream = new StreamReader(receiveStream);
  }
   else
  {
      readStream = new StreamReader(receiveStream,                                                    Encoding.GetEncoding(response.CharacterSet));
  }

   string data = readStream.ReadToEnd();

   response.Close();
   readStream.Close();
}
Green Falcon
  • 818
  • 3
  • 17
  • 48
Kronos
  • 41
  • 5
  • And what do you want use to render the html, css and parse compile and run javascript? – Tinwor Oct 25 '16 at 17:24
  • 1
    You need a browser component to **translate all data**. Why do you not want to use the Webbrowser component ? – Jim Oct 25 '16 at 17:28
  • https://www.youtube.com/watch?v=on2YpAIjOkU – Vishwa Ratna Oct 25 '16 at 17:35
  • @Tinwor i only need to display the html received from the response and also associated error code 400s etc – Kronos Oct 25 '16 at 19:08
  • @Jim it part of the requirement to not use the web browser class – Kronos Oct 25 '16 at 19:08
  • @vishwaratna the code makes use of the c# web browser class – Kronos Oct 25 '16 at 19:09
  • So you want display only the html without any render? – Tinwor Oct 25 '16 at 19:11
  • yeah, @Tinwor like for the code above i used a stream reader to output the html to a rich text box – Kronos Oct 25 '16 at 19:19
  • 1
    So why can't you take your response and put it in a RichTextBox if you don't want to render it? `string data = readStream.ReadToEnd(); richTextBox.Text = data;` – Sal Jul 09 '18 at 20:24
  • There is a product called [Awesomium](http://awesomium.com/) based on Chromium/WebKit. Their web site is under maintenance right now. . For .NET, it uses the [AwesomiumSharp](https://github.com/khrona/AwesomiumSharp) wrapper. I think, this is for WPF. You can dig inside for more details as I pasted for your reference. Related article [here](http://chriscavanagh.wordpress.com/2010/10/04/a-real-net-4-0-webbrowser/) You can google for more information on this. – Gaurang Dave Jul 11 '18 at 03:02
  • I'd agree with Gaurang here, and say using the a chromium .net wrapper (I use CefSharp), is 100% the way to go. The reason is that a webpage may continue running code after first load, and as a result of that code running subsequently change the webpage's content in some way, thus, you need a browser to run that code, handle the web requests, and tell you when the webpage has fully loaded. There's an "Off-Screen" version too, meaning there's no rendering going on. – Dan Rayson Jul 11 '18 at 10:44
  • @Sal my aim to use HTML is that, I make my reports in HTML format and send it to Printer for Printing, as you see its has table, when I printing it using web browser of .Net then table border is cutting on page break but not cutting in chrome – Imran Ali Khan Jul 12 '18 at 06:12
  • See [How to get started building a web browser?](https://stackoverflow.com/questions/598841/how-to-get-started-building-a-web-browser) discussion on StackOverflow and [How Browsers Work: Behind the scenes of modern web browsers](https://www.html5rocks.com/en/tutorials/internals/howbrowserswork/) article by Tali Garsiel and Paul Irish – Leonid Vasilev Jul 12 '18 at 07:40
  • @ImranAliKhan if your end goal is to iust print html, you can either play with the print margins to make it fit the page, or use one of the countless PDF libraries that can convert html to pdf. I feel like you're making this more complicated then it needs to be. – Sal Jul 12 '18 at 11:03

1 Answers1

2

GeckoFX and CefSharp are the most updated packages (you can find them on NuGet) to embed a browser in your application.

I think that writing a web browser from nothing should be too much hard and expensive.

Francesco
  • 130
  • 6