0

I have to create a webbroswer in wpf that supports all the sites and scripts and play video , I have created but some site got crashed and not supporting . Please provide solution.

Bhola
  • 11
  • 4
  • 2
    I suspect you use the `WebBrowser` control and are not actually trying to build a web browser by yourself. If the `WebBrowser` control doesn't support everything you require, you will have a hard time modifying it. What site did it crash on? – Tomáš Hübelbauer Nov 26 '14 at 10:11
  • I tried this www.flipkart.com it is showing errors this is not supporting so and so ... I am using webbrowser control for this how can I do that ? – Bhola Nov 26 '14 at 10:44
  • I've posted my follow-up as an answer, because I believe I have exhausted the options you have and offered all reasonable alternatives to your current approach. – Tomáš Hübelbauer Nov 26 '14 at 11:55

1 Answers1

1

What you ran into are probably error dialogs caused by JavaScript script errors. WPF WebBrowser control currently doesn't support disabling these dialogs and ignoring the errors. The WebBrowser control is based on Internet Explorer core and will have a hard time dealing with broken JavaScript, webpages will also sometimes report the web browser as old and inform the visitor about it, like FlipKart does.

One solution is to use WindowsFormsHost and host a Windows Forms equivalent - WebBrowser control - in it. The WF WebBrowser offers a property called SupressScriptErrors, which is not implemented by the WPF WebBrowser. That will hide the error dialogs for you, but you will still occasionaly receive a warning from the website saying they don't support the web browser used. That is out of your control unless you want to take a route of hacking the control to send a different User-Agent string and that will only fool broken UA detection, feature detection will still fail for things like HTML5 video, WebRTC and the like. More on this here.

You can also choose to embed Gecko (Firefox rendering engine) or Chromium. see here for more information on embedding alternative rendering cores as an alternative to IE COM wrapper offered by the framework.

Edit: this is also a possible solution, as it would seem. You will have to test it for yourself, though. I expect it to have less overhead than the WindowsFromHost element and although this uses reflection to develop against implementation, not interface, my opinion is it's safe to say the underlaying API in unlikely to change.

Community
  • 1
  • 1
Tomáš Hübelbauer
  • 9,179
  • 14
  • 63
  • 125
  • what about chromiumembedded with .net wpf ? How can I use this in my project ? – Bhola Nov 28 '14 at 09:28
  • The safest bet is to use Package Manager Console window in Visual Studio to install [`CefSharp.Wpf`](http://www.nuget.org/packages/CefSharp.Wpf/) library. This should do everything for you and you'll be able to use the Chromium renderer right away. Check out the project's [ReadMe.md](https://github.com/cefsharp/CefSharp) file for more information. – Tomáš Hübelbauer Nov 28 '14 at 09:51
  • [Here](https://github.com/cefsharp/CefSharp.MinimalExample)'s a repository with minimal example that should get you started. Please keep in mind that in order to use the Nuget packges, currently you are required to set the platform target in project's properties to x86 or x64 specifically, AnyCPU will not work ATM. – Tomáš Hübelbauer Nov 28 '14 at 09:56
  • Thanks for supporting .. I have added the package in package manager Install-Package CefSharp.Wpf -Version 33.0.2 but now I am not getting how can I use that or how to move further to refer it and use it ... – Bhola Nov 28 '14 at 11:08
  • Download [this repository](https://github.com/cefsharp/CefSharp.MinimalExample/archive/master.zip) as a ZIP file or clone it using Git. In the MainView.xaml file, comment out the `cefSharp:ChromiumWebBrowser` tag, build the solution, uncomment the tag and build again. Visual Studio sometimes gets confused if you have referenced assemblies and build for the first time, you will have to do it only once. This is a minimal example for both Windows Forms and WPF. – Tomáš Hübelbauer Nov 28 '14 at 15:11
  • I tried that solution while running that project it is working fine but I tried to apply those in my project I am not able to implement those in my project. I have installed the package using package manager and then tried to use the control but not found the reference of cefsharp. Please tell me from where can I add the reference to my solution ? – Bhola Dec 01 '14 at 05:09
  • I have tried it for myself and I also had trouble integrating the `ChromiumWebBrowser` control from scratch. I am affraid I cannot devote enough time to this to resolve it. My best advice is to run `diff` tool on solution directories of the minimal example repository and your attempt to see what's missing and working up from there. Good luck. – Tomáš Hübelbauer Dec 01 '14 at 10:57
  • I have added my pages and controls in that solution and implemented my required functionality but still it is headache I am not able to handle the events means I want to make it is visible true and false on some conditions but it is not working. – Bhola Dec 01 '14 at 13:22