Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mono WebBrowser control on Linux

I'm writing an application that I would like to have run under either Windows or Linux. Since it is a text application, the obvious choice for rendering and user interaction is to use html in a WebBrowser control. This all works great using Mono in Windows, but I'm absolutely stumped on how to get it to work using Mono in Linux. I'm running Linux Mint 17, have MonoDevelop and Firefox installed. The following code snippet compiles and runs, but when the application launches, wbMain does not show up. The application dies when trying to render an html string using wbMain.

private System.Windows.Forms.Panel pnlMain;
private Mono.WebBrowser.IWebBrowser wbMain;
private System.Windows.Forms.Button btnGo;

this.pnlMain = new System.Windows.Forms.Panel();
this.wbMain = Mono.WebBrowser.Manager.GetNewInstance();
this.wbMain.Activate();
this.btnGo = new System.Windows.Forms.Button();
this.pnlMain.SuspendLayout();
this.SuspendLayout();
// 
// pnlMain
// 
this.pnlMain.Controls.Add((System.Windows.Forms.Control)this.wbMain.Window);
this.pnlMain.Controls.Add(this.btnGo);
this.pnlMain.Location = new System.Drawing.Point(12, 1);
this.pnlMain.Name = "pnlMain";
this.pnlMain.Size = new System.Drawing.Size(260, 248);
this.pnlMain.TabIndex = 0;
// 
// wbMain
// 
this.wbMain.Resize(260, 216);
like image 289
Jon Avatar asked Oct 20 '14 22:10

Jon


1 Answers

this.wbMain = Mono.WebBrowser.Manager.GetNewInstance();

The problem lies with your GetNewInstance() from what I understand here. GetNewInstance assumes platform of Windows by default, you need to pass in your own Mono.WebBrowser.Platform for it to render in the framework you want (like Gtk).

Source Code

You can see in the source code I linked, the default GetNewInstance() returns Platform.Winforms;

    public static IWebBrowser GetNewInstance ()
    {
        return Manager.GetNewInstance (Platform.Winforms);
    }

Also Mono.WebBrowser has been retired in favor of WebkitSharp. You really should be using WebkitSharp to do this now. WebkitSharp has had...some issues, so there's a currently open version of it called open-webkit-sharp that may work for you as well. The code on there is at least up to date as of 2012. Whereas Mono WebBrowser and webkit-sharp haven't had any major code changes...in years, at least 5 to 7 years.

I've also had good luck with the open version of Awesomium, and it's a staple of the gaming industry. Again, the open version of Awesomium hasn't had any major updates since 2012 though. However, you can get the paid version of Awesomium if money/cost isn't an issue and that has had recent updates.

like image 196
Brian Deragon Avatar answered Oct 15 '22 08:10

Brian Deragon