WPF Chromium WebBrowser source code!

UPDATE: New version available for .NET / WPF 4.0 here!

The source code for my WPF Chromium WebBrowser control is now available on CodePlex.

The source includes:

Cjc.ThreeDeemium – The sample application, currently without any 3D features.  Go figure.
Cjc.ChromiumBrowser – The WPF Chromium WebBrowser control.  Depends on Cjc.AwesomiumWrapper and the two Awesomium / Chromium C++ DLLs (Awesomium.dll and icudt38.dll).
Cjc.AwesomiumWrapper – A Managed C++ / CLI wrapper around Awesomium.  This is much easier to maintain than the old P/Invoke stuff, and is almost nice to look at 🙂
Awesomium – C++ headers and libraries for Awesomium / Chromium.

There’s also a bonus project 🙂 :

Cjc.WebSnapshot – A small command-line utility using Cjc.AwesomiumWrapper to snapshot a URL (you need to specify a full URL including the scheme – https://chriscavanagh.wordpress.com etc).

219 Comments

  1. You know I had a funny incident. I was driving to Madison from Chicago and there was a nasty traffic snarl that turned the highway into a parking lot. My comment to my wife “It’s probably just people staring at an accident. I swear there better be a car just engulfed in flames up ahead.”

    Sure enough we get a few miles down and there it was. Not just smoke coming out…this thing was litterally engulfed in flames. That was the first time I felt that traffic congestion was justified.

    Reply

  2. Great ! I we could have the same for the native one…

    I noticed some bugs because they are frequently crash when navigating. Can’t remember when, but it’s problematic if you want to use it in a production environement…

    Reply

  3. FremyCompany – Any crashes are more likely caused by my demo app than the wrappers or Awesomium/Chromium. If you could send me examples of what causes it to crash I’ll take a closer look.

    Keep checking back though; I’ve been publishing a few fixes that might help.

    Reply

  4. FremyCompany – I’ve published a number of bugfixes that might help. Note it won’t work well with Java applets or XBAPs (yet… although I’ve not looked closely at it so far)

    Reply

  5. squid – It might be my eyes, but the webpage looks a little blurry in the screenshot (compared to the rest). Make sure your backbuffer pixelformat is bgr32 or equivalent (think that’s what Awesomium defaults to). Hope this helps! 🙂

    Reply

  6. hi
    i want to know how can we use C++ class libraries with P/invoke?
    and i have a problem with the wrapper
    i added a reference to the wrapper and put those 2 C++ DLLs in my project folder (i don’t know how can i reference them) and when i try to use the library it says filenotfound exception???
    what was wrong in what i did?

    Reply

  7. Ashkan – There are two native C++ DLLs (Awesomium.dll and icudt38.dll). It seems you can actually omit the icudt38.dll if you don’t need keyboard input or Javascript support (don’t know if that’s deliberate though).

    The Cjc.AwesomiumWrapper.dll assembly is a Managed C++ wrapper around Awesomium.dll. You can use it directly in a .NET project with no need for P/Invoke (FYI internally it uses C++/CLI which is more intuitive and easier to work with than P/Invoke).

    If you include the two native DLLs, make sure you set them as “Content” (so they’ll get published etc with your project) and set “Copy to output directory (always / if newer; either is fine). I’m guessing the problem is they’re not present in your Debug / Release folder (when running through Visual Studio). There’s no reference as such to the native DLLs; they’re just expected to be in the same folder.

    Hope this helps!

    Reply

  8. Hi!, Yes you see blurry because I left the bloom effect in the game. I’m making a custom component with your wrapper library. When I’ve tested I’ll send you the source code. The screenshot is only a test!

    bye squid

    Reply

  9. kal – Right now you need to hunt around for the source code (try here: http://forum.quest3d.com/index.php?topic=67161.45). All existing Awesomium code is open source, but it looks likely later versions won’t be. There’s a v1.5 “coming soon”, but I’m not sure what the licensing terms will be.

    In any case, it’ll probably be worth creating a new project on CodePlex (or wherever) with the most recent LGPL source. Most of the hard work has aready been done by Adam (http://princeofcode.com/blog/) so aside from a few tweaks along the way, just periodically rebuild the native DLLs with the latest Chromium source…

    If the latest binaries were always readily available for download, it could make a lot of developers very happy (including me; I’ve served my time with C++ already 🙂 ).

    Reply

  10. Hi Chis!

    This is stunning. How did you come up with an idea like this?

    The binary run fine, but the window1.xaml in the CJC.ThreeDeemium project reports “The spesified module could not be found. Exception from HRESULT 0x8007007E” and the Address property in the control of that template is marked with an error

    So it won’t compile. Strange..

    Reply

  11. Rune – If you’re running a debug build, it’s probably looking for Awesomium_d.dll. That’s about 50MB so I didn’t upload it to CodePlex 🙂 You could either run in Release, or try these steps to get the debug DLL:

    1) Download 3rd.zip.001 – 003 here: http://forum.quest3d.com/index.php?topic=67161.45
    2) Merge them into one zip:

    copy /b 3rd.zip.001 + 3rd.zip.002 + 3rd.zip.003 3rd.zip

    Another option is to get all the Awesomium and Chromium source and build from that… See my earlier comment for some details on it.

    Reply

  12. You were right 🙂 The debug dll is the solution.

    The xaml viewer inside Visual Studio still goes crazy about this error so the view can’t be redrawn, but it compiles, runs and lookes pretty cool generally.

    Could live with that..

    Reply

  13. There might be somewhere you can drop the DLL where VS will see (and use) it, although ideally my ChromiumBrowser control should probably be smarter about how it renders at design time… I’ll update here when it’s fixed 🙂

    Reply

  14. Thanks for the quick reply Chris! I was just dumping the debug dll into my system folder which VS holds a path reference to and the xaml viewer redraw perfectly!

    Even the Address shows up inside the viewer. Cooler than ever.

    Reply

  15. Great post!
    One thing I’m attempting to do is use your control to capture a complete image of a webpage. Would you have any ideas on how I would go about that?

    Reply

  16. Chuck – This is pretty much what you’d need:

    using CAW = CjcAwesomiumWrapper;

    public static Rect? RenderSnapshot( string url, byte[] buffer, int width, int height )
    {
    using ( var webCore = new CAW.WebCore() )
    {
    using ( var webView = webCore.CreateWebView( width, height ) )
    {
    webView.SetTransparent( true );

    var finished = new ManualResetEvent( false );
    var listener = new CAW.WebViewListener();
    listener.FinishLoading += delegate { finished.Set(); };
    webView.SetListener( listener );

    if ( url.StartsWith( “file:” ) ) webView.LoadFile( url );
    else webView.LoadURL( url );

    var timeout = DateTime.Now.AddSeconds( 30 );

    while ( !finished.WaitOne( 100 ) )
    {
    webCore.Update();

    if ( DateTime.Now > timeout ) return null;
    }

    var r = webView.Render( buffer, width * 4, 4 );

    return new Rect( r.X, r.Y, r.Width, r.Height );
    }
    }
    }

    Reply

  17. Chuck – The CodePlex/SVN source now includes a “WebSnapshot” sample project. It’s a simple command-line utility to save a page snapshot to a file (currently always saves in .PNG format, with transparency… could probably used a few more options to be useful).

    Reply

  18. Hmm 1 Minor problem Chris if you don’t mind taking a quick look at it. I ran the program and it gives me blank png’s of the websites I plug in. I took a look at the code and can’t really find where or what the problem may be. If you get a chance could you give it a look please?
    Thanks!
    Chuck

    Reply

  19. Chuck – Are you able to step through with the debugger? Make sure the URL you’re using includes the full scheme etc (http://www.google.com); it won’t automatically add those. Also, you might want to change the project to use a BGR32 image and remove the webView.SetTransparent( true ); (I’ll probably remove those anyway; I doubt many users would want transparent backgrounds)

    Reply

  20. Hi Chris,
    This is great – I’ve extended the control now so you can pass a html string to it instead of a url.

    The only thing is I need to be able to get the full size of the html page – any chance you could help me? I’m trying to execute some javascript to return the size using webView.ExecuteJavacriptWith Result but I’m not having much luck!

    Thanks,

    Wayne

    Reply

  21. Can’t get anything to work…looks as though any reference to the Awesomium dlls have been “changed” in codeplex so you can’t use them?…or am I doing something stupid?

    Reply

  22. looks like it’s me being stoopid…(now there’s a suprise 🙂

    Still getting blank browsers in Threemium and youCube3 projects…but they build, and I can step through the code.

    Might be my firewall…
    p.s. ignore my last post… I was having a “blonde” moment.

    Reply

  23. John – Is the browser window all white, or black? If black, it suggests a problem calling the Awesomium methods. It’ll only be white if Awesomium successfully rendered something.

    Do the ClickOnce demos work for you, or same problem? Also, are you on an x86 or x64 OS?

    Reply

  24. Hi Chris…it was authentication issues (white pges, not black). When I changed the url to a page on the company intranet I got a page rendered. I’ve searched on it and it looks as though it’s Chromes inability to authenticate based on your windows login info.
    Thanks for getting back to me so quickly

    Reply

    1. Chris, John,

      I have the same issue (white pages), probably also because of the authentication.
      Is there any way to submit user credentials in this control? (Google chrome asks for user credentials via a popup window, but WPF Chromium Browser does not).

      Reply

      1. Pieter – Currently there isn’t a way to submit credentials. I’m kicking around the idea of a managed port of Awesomium (Chromium itself would need to remain native C++ obviously) which could allow us to control pretty much everything… The case for it is certainly building 🙂

  25. I’m trying to use the ExecuteJavascriptWithResult function which returns a FutureJSValue but I dont know how to use that with the wrapper. Is that implemented or do i need to tweak it?

    Reply

  26. Wrapper Issue – It might need some tweaking. I exposed the methods but haven’t tested them yet. If you let me know what you change I’ll update the source (or could add you as a contributor on CodePlex if you prefer).

    Reply

  27. I have been playing with it, but getting an exception from my code. Here is the definition:

    JSValue^ Get() {
    Awesomium::JSValue val = this->value->get();
    return %CjcAwesomiumWrapper::JSValue(val);
    }

    (I wrote it this way because I was trying to overcome an exception being thrown)

    When this-value->get() is called and assigned to a new object, an exception is thrown:

    Attempted to read or write protected memory. This is often an indication that other memory is corrupt

    I was reading up on this exception, and some say it has something to do with the build configuration (i.e., all the files need to be built for x86 for instance). I’ve been experimenting to get past this exception but no dice thus far. I’m wondering if Awesomium_d.dll needs to be built correctly as well or if I just have to worry about the wrapper and whatever the wrapper is using.

    Your input would be much appreciated.

    Reply

  28. Matthew – Take a look at Cjc.AwesomiumWrapper; the JS/callback methods are implemented there but I’ve not exposed them on the WebBrowser control yet. It looks like you call SetCallback and give it the name of a method to “register”, then attach to the Callback event of the WebViewListener (where I’ve mistakenly called the first param ‘url’ instead of name). I can kick this round a bit and post an update if it helps…

    Reply

  29. Fredrik – It’s probably because VS can’t see the native DLLs. Also, it might be trying to use the debug version of Awesomium (Awesomium_d.dll); I excluded that from the source as it’s about 50mb (vs 8mb for the release). If you drop the DLLs somewhere VS will look, it should work ok in the designer. Ideally the WebBrowser control should handle design mode better, but would probably need a tweak to load the Awesomium dll dynamically… Hope this helps!

    Reply

  30. I have successfully integrated the browser control in my application, and in general it works without flaws and obeys my WPF transforms etc. – great 🙂 BUT I do have a huge problem, though – trying to instantiate the Cjc.ChromiumBrowser object on an x64 OS makes the application crash (tried both XP x64 and Vista x64). The hosting application is not x64 itself, but it has always run nicely on x64, as any windows application should be able to do. Now it starts up fine and work ok, until you bring up the window containing the Cjc.ChromiumBrowser component. Then it crashes immediately:
    Cannot create instance of ‘WebBrowser’ defined in assembly ‘Cjc.ChromiumBrowser, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’. Exception has been thrown by the target of an invocation.
    The inner exception is that the module or one of it dependencies cannot be found. Everything is fine when OS is not x64.
    Have someone experienced (or even solved) this?
    Thanks,
    Jesper.

    Reply

  31. Just for the record – the problem turned out to be related to the hosting application being built for “Any CPU” (VS project settings) and the browser components and wrapper being built for x86. This difference caused a runtime crash on x64 OS. Changing the hosting application build settings to x86 fixed the problem.
    Best regards,
    Jesper.

    Reply

  32. ralph – It looks like it “tries” to open; it shows Adobe Reader’s dark gray background. It might be the same problem that affects some Silverlight apps which need to use the browser’s HTTP stack (Silverlight 3 has its own networking stack, but you have to “opt in” afaik).

    This might be something that’s resolved with the next version of Awesomium; unfortunately the latest available Awesomium source doesn’t play nicely with the latest Chromium source 😦 (so can’t just go and rebuild it). We’ll need to see if/how there remains an open-source version of Awesomium beyond v1.5…

    Reply

  33. I grabbed the latest from CodePlex, Set #29203, and even after removing the missing files from the projects, and making sure the Awesomium DLL’s are in the Cjc.ThreeDeemium bin, I get an error trying to run the demo project. Am I missing something simple here? Is there not a SLN that works out of the box?

    “Cannot create instance of ‘WebBrowser’ defined in assembly ‘Cjc.ChromiumBrowser, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’. Exception has been thrown by the target of an invocation. Error at object ‘grid’ in markup file ‘Cjc.ThreeDeemium;component/window1.xaml’ Line 22 Position 4.”

    Reply

  34. Brett – Is this a runtime error, or is it thrown by VS’s designer? If VS, you’ll need to make sure you have Awesomium_d.dll somewhere VS can find it (it’s a native DLL). The solution should build fine otherwise, but let me know if that’s not the case 🙂

    Reply

    1. The error is a runtime error. I don’t have the Awesomium_d.dll as it was one of the missing file in the project, which I removed. I don’t seem to see the Awesomium_d.dll anywhere else in the ZIP, except in the Awesomium/lib, but it’s just a lib, not dll. Where do I get the Awesomium_d.dll?

      Reply

    2. wpfchromium-29203.zip

      Out of the box, the projects are missing files. FYI.

      – Cjc.WebSnapshot –> missing
      Awesomium.dll
      Awesomium_d.dll
      icudt38.dll.

      – Cjc.ThreeDeemium –> missing
      Awesomium_d.dll

      Reply

  35. Brett – Do a quick search through the comments above for Awesomium_d.dll. Basically it’s a huge file so it wasn’t practical for me to put on CodePlex, but currently you’ll need it if you’re running a debug build. There’s a forum link posted in the earlier comments which should help.

    Note the Awesomium DLLs (Awesomium, Awesomium_d and icudt38) aren’t built by me. The latest Awesomium source I’ve got doesn’t build against the latest Chromium source, so unless someone’s able to throw some time at this (either fix Awesomium, or get the relevant older Chromium version to build against), we’re stuck with these binaries until Adam (http://princeofcode.com/about.php) clarifies which direction he’s going with licensing future versions.

    For Cjc.WebSnapshot, just copy Awesomium.dll/icudt38.dll into its folder.

    Hope this helps!

    Reply

  36. Got it, I’ll dig through the posts. Thanks!

    One final questions, which I think the answer is yes from the screen shots I’ve seen…but does the ChromiumBrowser work with AllowsTransparency in the main window? I know the WPF WebBrowser control doesn’t because of the layered windows issue (not sure if MFST if going to have a workaround for that or not). All I’m trying to do is host web content within my custom chromed main window. 🙂 Something so easy that used to work pre-SP1.

    Reply

  37. Brett – Not sure on inbuilt WebBrowser; maybe it doesn’t support windowless mode? (wild guess, probably wrong).

    Fyi ChromiumBrowser/AwesomiumWrapper tweaks the rendered html slightly to make the page background color transparent.

    Reply

  38. Hey Chris, I’m back to the JS callback. I can’t seem to figure this out. If you could post an update like you mentioned way back in September or possible give me an example I’d really appreciate it. -Thanks!

    Reply

  39. Regarding the above post i’ve tried this…

    In the WebBrowser.cs class in the InitWebView method I’ve added

    webViewListener.Callback += delegate(string url, JSArguments args)
    {
    if (CallbackFired != null)
    {
    Dispatcher.BeginInvoke(
    (Action)delegate { CallbackFired(this, new CallbackEventArgs(url, args)); },
    DispatcherPriority.Normal);
    }
    };

    And then in the test app I do…

    InitializeComponent();
    browser.Source = Settings.Default.DefaultUrl;
    browser.CallbackFired += new EventHandler(browser_CallbackFired);

    void browser_CallbackFired(object sender, Cjc.ChromiumBrowser.WebBrowser.CallbackEventArgs e)
    {
    MessageBox.Show(e.Url);
    }

    But no where do I call .SetCallback(); I don’t see this method exposed at all. Any ideas? (Sorry if the code paste is bad)

    Reply

  40. Chris, So i have the callback firing but now it seems impossible to get the arguments passed to JSArguments. I tried doing something like std::string value = args[0].toString(); in the wrappers OnCallback method but no go. Any ideas? (Sorry for so many posts!)

    Reply

  41. Matthew – You’ve uncovered my shameful lack of testing 🙂 I’ve fixed the (many) bugs with callback (and implemented missing methods like ExecuteJavascript) and updated the source on CodePlex. Here’s an example of how you might use a callback:

    browser.Initialized += delegate { browser.SetCallback( “myCallback” ); };

    browser.Callback += delegate( object sender, Cjc.ChromiumBrowser.WebBrowser.CallbackEventArgs args )
    {
    var test = args.Arguments.Select( a => a.ToString() ).ToArray();
    ….
    };

    Then in your javascript, you can invoke your callback method on the “Client” object like this:

    Client.myCallback( “arg1”, “arg2”, 42 );

    Hope this helps!

    Reply

  42. Chris,
    I would like to use the Google Earth Plugin in your WPF browser. Unfortunately the plugin does not recognise Chromium, only Chrome.
    I propose to rebuild awesomium and chromium and hope to change the version info passed to the plugin.
    Even if I do this are there other problems I am not considering as the plugin uses Qt for it’s UI.

    Reply

  43. Eoin – I’m not sure if it’d work or not. Awesomium works great with Silverlight and Flash (mostly), but trips up with other plugins… Adam recently released “NaviDemo 2” based on the latest Awesomium version (1.5). You could try some sites in that in see if plugin support has improved.

    Hope this helps!

    Reply

  44. Chris – So the new version you gave me works great. I’ve been using the debug version up until now. I needed to go to release, so i switched to release mode and now when i run in release mode I get an error in AwesomiumWrapper.h at line array^ argArray = gcnew array( args.size() ); in method OnCallback with the error “Arithmetic operation resulted in an overflow.” however if i switch back to debug this error does not occur. Any ideas?

    Reply

  45. Chris, I have checked the settings and everything is good. I’ve even downloaded the latest version and did not modify the project at all and release build still gives the same overflow error. Any chance you might be willing to take a look at my solution? Thanks!

    Reply

  46. Hi,

    many thanks to you Chris for creating this gorgeous WPF control. You enabled me to put a WebBrowser inside a Popup with AllowTransparency set to true.

    Do you have any hints on how to downscale the displayed page? That way, that no scrollbars are needed any more. Or that the page width fits to the browsers width, to have only vertical scrollbars.

    Putting a Viewbox with Stretch set to Uniform didn’t work.

    What I want to achieve is a preview of the page. So it might also be more feasible to make a png snapshot of the whole page and to display it in place. Is the snapshot function already capable of an entire height snapshot?

    Reply

  47. Hi,

    First thank you for your contribution, it is really impressive.

    I am really new to C# so sorry if my question seems stupid:

    actually the webbrowser class inherit from System.Windows.ContentControl. However the original webbrowser (as well as the one that embedded gecko) inherit System.Windows.Forms.Control.

    I took a look at the code, but I must confess that I am a bit lost at how to make a webbrowser using the AwesomiumWrapper into a new WebBrowser class that inherit from System.Windows.Forms.Control

    Maybe someone have some advice.

    Thank you and Best Regards,

    Nicolas

    Reply

  48. Hi Chris,

    Just a short post to tell you that it worked fine.
    Endeed ElementHost was the solution (and a pretty nice trick).

    Thank you and best regards,

    Nicolas

    Reply

  49. Hi,

    does anybody know, how I can prevent the Webbrowser control from displaying ScrollBars when it’s to small to display the whole HTML?

    Reply

  50. Bogomir – Currently the only way [I’m aware of] is to make the control much larger and put it in your own ScrollViewer (or if you use AwesomiumWrapper directly you’ll have a bit more control). The problem there is knowing how big a bitmap to use (plus the bigger it is, the slower rendering will be etc). Ideally Awesomium/Chromium would report its current virtual page size and allow disabling of its scroll bars, but currently it doesn’t.

    Reply

  51. Hello,

    firstly I want to thank you for this awesome control, I have it hosted in an element host in a windows form. My question is, has anyone had a problem with the control using too much cpu? In slower machines it takes up to 30% maybe more.

    Thank you and best regards.

    Reply

  52. Is there a chance to modify your code to run it as a replacement for the WebBrowser control and use it exclusively in Windows Forms 2.0?

    If you tell me “yes” and it is possible in a reasonable time span, I will take a deeper look and try to move it back to .NET 2.0.

    Reply

  53. Hi,

    is it possible to remove the vertical scroll bar from the browser control?

    We plan to put 2 Textboxes and the web browser control in a vertical StackPanel. This StackPanel has an own ScrollViewer, so the user should scroll down all content using the ScrollViewers scrollbar – the scrollbar within the browser control should be removed (the control should render the full content – the user will bring it into the view when scrolling down).

    Is this possible?

    Bye,

    Tobias

    Reply

  54. Uwe – If .NET 3.5 is installed on the target machine, the simplest option would be to host this [WPF] WebBrowser control inside Windows Forms. Alternatively you could create a native WinForms control that uses the AwesomiumWrapper component (this is what the WebBrowser uses internally). If .NET 3.5 isn’t available at all, you might need to change/rewrite Awesomium wrapper to use regular p/invoke instead of C++/CLI.

    Fyi I’m kicking round the idea of a managed version of Awesomium with a minimal amount of C++ in it (just a thin C++/CLI wrapper around Chromium itself).

    Reply

  55. L – Are you seeing this behavior with the ClickOnce demo, or just when hosting the control yourself? If you’re hosting it, make sure AllowAsyncRendering=false. While that setting has its uses, it’s currently less efficient than synchromous rendering.

    Does the high CPU usage occur on all sites? Also, it would be helpful if you could try the same thing with “NaviDemo 2” (a native XNA app based directly on Awesomium – http://princeofcode.com/blog/?p=374). and let me know if it performs better or not.

    Reply

  56. Tobias – Currently the only way to achieve this is tell Awesomium to render to a bitmap that’s larger than the view size. Obviously this is only practical if you can determine a maximum page size to allocate, which is often difficult. Ideally Awesomium could tell us its current virtual page size, but currently it doesn’t 😦

    Maybe Awesomium 1.5 will have some support for this scenario. Alternatively if we go ahead with a managed version of Awesomium, this is something that could be taken into consideration from the start.

    Reply

  57. Thank you for your reply, I am not seeing the same performance issues with the click once demo. I am thinking that I see this in my app because I used the control to display flash..I will test more and post if I have anything new.

    I tried NaviDemo 2 and had almost the same amount of cpu load, but its a 3d app its bound to use more resources so I can’t really come to any conclusion. Also the AllowAsyncRendering property..I can’t find it,I am hosting in a regular windows form maybe that’s why.

    Thank you, L.

    Reply

  58. Hey Chris,

    Great work! Thanks for getting us a real wpf browser.

    Any plans to port this to 4.0 any time soon? I tried to compile in 4.0 beta 2, but it doesn’t work (and I haven’t had time to debug yet to see what exactly is going on).

    Reply

  59. Lol, sorry, I suppose that would be useful 🙂 If you grab http://dl.dropbox.com/u/21341/jstest.html and put it in c:\temp (or change the code to look elsewhere), once the app has loaded click “script test” (which registers a callback) then click the 2nd “Go” button in the web control. This fires a callback with 3 parameters and crashes the app.

    By the looks of things the parameters array contains nothing when it’s getting to your wrapper, so you’re probably right about the version mismatch, but I can’t seem to get it going with any version of the DLL that I have.

    Thanks again for the help.

    Reply

  60. Hi Chris,
    I’ve just taken the latest code from CodePlex, altered the ThreeDium code slightly to add a callback event hook and add a button to register the callback, then loaded the test file above into it and pressed the button and I get exactly the same crash. This is using the Awesomium binary and your library from CodePlex.

    Any light you could shed would be much appreciated – I’m getting nowhere myself 😦

    Thanks,

    Reply

  61. Hello Chris, any thoughts on why it’s not rendereing .pdf ? it will be huge to me to have pdf displayed inside wpf as it it was a xaml control..

    can u help me with that?

    thanks
    Rui

    Reply

  62. Rui – Do PDFs show in the regular Chrome browser for you? Make sure that works first. If still no luck, it’s likely to be an issue with “windowed” add-ins (similarly Xbaps and Java applets appear to have problems). There isn’t much we can do about this right now, but maybe the upcoming Awesomium version (1.5) will fare better…

    Sorry it’s not better news!

    Reply

  63. Hi Chris, sorry to bother you again. I just upgraded to beta 2 of visual studio and it seems it breaks the Webbrowser, generating a “The type initializer for ‘Cjc.ChromiumBrowser.WebBrowser’ threw an exception.” error,

    Any chance you got a version working for beta 2? I’m kinda relying on the Chromium webbrowser for my project so I’m screwed otherwise :/

    Reply

  64. Mattias – See the end of Sacha Barber’s related post (http://sachabarber.net/?p=597) – it mentions a tweak needed in your app.config. Let me know if it helps or not 🙂

    FyiI’ve deliberately not moved the code to 2010 yet; I’m waiting for one of these things to happen:

    1) Awesomium 1.5 is released (“soon”)
    2) VS2010 release candidate
    3) I replace Awesomium with a fully managed wrapper

    I’m liking option 3 more and more, but it’s a hefty time commitment… Still pondering 🙂

    Reply

  65. Ahh, that worked, thanks!

    Awesomium is a really great alternative right now, but one has to ask if Microsoft won’t release a webbrowser that supports wpf with ie9.

    Unfortunately IE is a bit too slow compared to other browsers right now but the new DirectWrite stuff coming in ie9 might make it a viable candidate, might be a ways off though :/

    Reply

  66. Hello Chris, yes the pdf’s work in the normal chrome, as you said i think is thw awesomium dll… it’s a petty 😦
    it will much better to put this control isntead of the normal wpf webbrowser, if u have some news about this please hit me back an email.

    Thanks
    Rui

    Reply

  67. Hi Chris,
    I am building an application that has some RSS reader functionalities. Once the user sees the RSS in my application, I am trying to get the links in chromium to open the user default browser (target=_blank)…

    It seems that this is blocked by Awesomium… any work around you can propose (except waiting for 1.5 :-)!)

    Thanks a bunch!

    Reply

    1. benjoTLV – If you’re using the browser demo I posted (Clickonce thing, non-3D), there’s a ‘debug’ checkbox you can click. It should show all events that are raised by Awesomium (which WebBrowser just echoes). See if clicking the links makes anything appear in the debug log and let me know…

      Reply

      1. BenjoTLV – Interesting… What version of Flash is it built for? Prior to v8 (I think) the only way to navigate was with getURL( … ). Later stuff might be using ExternalInterface to call into some Javascript… Would be interesting to know if this applies to all Flash (and SilverlighT?) content or not…

      2. I don’t know for which version of Flash it is but I tested it in couple of websites including http://www.cnn.com
        You can see in debug in your browser that the ads get loaded (beginNavigation, beginLoading) but clicks on ads raise no events at all

        In addition, I don’t want to kill your Christmas challenge but if you are interested I found a working dll (not crashing on release with oncallback…) here: http://speps.fr/awesomiumdotnet

        I will try to solve the flash bug using some Javascipt and the callback and will report later… if you find a better solution I’ll be glad to get it 🙂

      3. I don’t think the bug applies to all Flash, it seems to me (but I am not sure) that it is related also to the fact that the flash is in another iFrame. At least when it is not, I can get the flash object in my oncallback so I can trick the click event…

        I tried to go to silverlight.net and play with the silverlight showcase applications through your browser: clicks there have an unpredictable behavior! sometimes they work, sometimes they are misplaced, sometimes they don’t do anything!

        The awesomium.dll I gave you the link to is the princeofcode one, version 1.08, unchanged. But if you would like the source codes + some improvements done by others, I found this nice link http://github.com/pathorn/awesomium. IT is the latest 1.08 version in open source with some other contributions – I did not test it but maybe it can help you

        Good luck!

      4. Hi,
        I did some more testing on the Flash issue above and I think I know what the problem is even though I have no idea how to solve it!

        The problem seems to be that the browser is not getting the calls triggered by the Flash – like navigate to URLs (ClickTAGs). As a consequence, events/actions that are staying in Flash are working (click on play or pause in youtube for example) but events in Flash that are supposed to call back the browser are not working.

        Anyone else experienced the same? does anyone has a solution or at least a direction to solve this?

        Thanks

      5. benjoTLV – I’ve not found anything new about it yet… So to summarize, it looks like Flash is unable to call into Javascript when inside Awesomium/WebBrowser? If you go to Hulu (http://www.hulu.com) and click one of the Flash links on the home page, does navigation work then? (I’m assuming it’s just using Flash’s getURL rather than ExternalInterface).

      6. Actually navigation within the flash object but not from flash to the browser…
        For example in Hulu, clicking on the main flash banner in the home page works like it does on a youtube videa or any other flash object but no info/event is sent back to the browser.

        The best way to understand the problem I think is to try to click on a flash ad or by right-click on a youtube video and try select “watch on youtube” then you will see that nothing happen.

        In addition, when you use the regular Chrome browser, if your cursor is on top of a flash object, it will be turned into an hand (which I guess means that the flash tells the browser that an action is possible). In awesomium, the cursor stays an arrow which I assume means that Awesomium is not getting the info from the flash…

        I experience this even with your click-once app as well as the NaviDemo 1.0 and 2.0 so I guess it is related to awesomium.

        Any idea?

      7. OK!! Now I do understand the test you asked me to perform… Sorry!

        Yes! Clicking in the flash in hulu does navigate outside of the flash object!!! in the regular browser, it opens a new tab and in awesomium, it opens it in the calling frame (as it is supposed to work)

        So your assumption seems to be right. It does getURL but not externalInterface.
        Any solution in mind?

  68. Hi Chris,

    great control, amazing work – exactly what I’ve been looking for! 🙂

    Two questions / problems though:

    1) This one seems related to the issues others already raised regarding scrollbars – I just hope there’s a good solution to it: When ChromiumBrowser is first rendered within its containing control, the content is displayed at 100% size, with scrollbars showing, since the container is too small to display the entire page (and this is fine). However, when the user resizes the container, I would expect a larger / smaller portion of the content to be displayed, changing or hiding the scrollbars, instead of maintaining the same portion, and scaling the content. Any idea how to achieve this?

    2) My current task is to add multi-touch functionality to the browser (panning, zooming and clicking, using contact events, for use on a multi-touch desk similar to MS Surface). Without having looked at your source code in too much detail yet, what would you recommend as the best way to go about this? Is a multi-touch layer on top of ChromiumBrowser sufficient, or would I rather derive from it, or, worst case, have to branch and modify the code itself (IOW, build directly on the AwesomiumWrapper component)?

    Thanks so much in advance for your feedback!

    Reply

    1. guido – Thanks for the questions!…

      1) What container do you have the WebBrowser inside? As long as you have HorizontalAlignment=”Stretch” (and VerticalAlignment=”Stretch” – both the defaults I think), it should resize to fit the container, showing more/less content as needed (ie, it won’t scale). Does the ClickOnce demo I posted (non-3D) behave the way you expect, or did I misunderstand?

      2) Do you already have some multi-touch stuff going on in WPF generally, or are you only wanting to touch-enable the WebBrowser? Are you using the Surface SDK?

      Reply

      1. Thanks for your replies, Chris! 🙂

        1) Oops, my bad… Yeah, indeed: I did overlook that your ThreeDeemium sample does actually behave as expected – the problem is with my container, which (indirectly, through a Border and a Grid) is an XViewerControl (from the xdesk SDK, comparable to a ScatterViewItem in Surface SDK). Upon resizing, this control will simply apply a ScaleTransform to itself and it’s content, which of course explains the behavior I observed. I need to figure out myself now how to get around this, like applying an inverse transform to the Browser control – something along those lines.

        2) Yes, I’m already doing a lot of multi-touch stuff in WPF, using not Surface SDK, but impressx’s xdesk SDK (http://www.impressx.com/index.php?option=com_content&view=article&id=46&Itemid=58&lang=en). Quite some of our projects also require a touch-sensitive, resizable and rotatable WPF web browser control, and this is where WPFChromium finally and thankfully comes in so handy! As for the multi-touch support, we basically have the following requirements:

        a) Simple touch events (ContactDown / ContactUp) in the content area should be interpreted as mouse clicks, like clicking buttons / links etc. I have figured this out, but had to modify WebBrowser.cs, and use Awesomium’s InjectMouseDown() etc.

        b) ContactChanged (analog to mouse dragging) events should be used for panning / scrolling of the content. No idea yet how to go about this, since Cjc.AwesomiumWrapper doesn’t seem to offer any methods for scrolling the content. Any ideas?

        c) Relative diplacement of 2+ contacts (“pinch” / “unpinch”) would scale the content. I am hoping to get this done by again applying a ScaleTransform to the browser.

        I’m thankful for any ideas and suggestions.

        Thanks again,

        Guido

  69. Hi,
    I have the same problem as Matthew and Steve Robbins regarding the oncallback with arguments throwing a very big error (arithmetic something…) and I found that it is an awesomium problem. see this http://princeofcode.com/forums/viewtopic.php?f=9&t=30&start=0&hilit=oncallback

    The solution is to rebuild and compile chromium and awesomium in MSVC9 (using only this) and then both the release and debug version should behave the same (and work!)
    Unfortunately I failed doing that (building Chromium is a very difficult task I don’t seem to cope with).
    Does anyone already did it and can post/send me the dlls??

    Thanks!

    Reply

    1. Did you ever have any luck with building this/finding the dlls? I’m trying to stick with the LGPL version of awesomium but can’t really unless I can get the callback function working.

      Cheers!

      Reply

  70. Hi Chris,
    Sorry for all these comments during the holidays period, I guess you don’t have a lot of time to read them! Happy new year BTW

    I noticed that flash banners (ads) are not clickable in your browser (as well as in NaviDemo 2.0 from PrinceofCode). Do you know if there is anything to do about it?

    Reply

    1. benjoTLV – See my earlier comment… maybe the “debug” log checkbox will reveal something. If the events are getting thrown, we probably just need to open a new window (?) and navigate to it. If not, I (we?) can probably dig into Awesomium a bit and see what’s up…

      Happy new year to you too! 🙂

      Reply

  71. I don’t think the bug applies to all Flash, it seems to me (but I am not sure) that it is related also to the fact that the flash is in another iFrame. At least when it is not, I can get the flash object in my oncallback so I can trick the click event…

    I tried to go to silverlight.net and play with the silverlight showcase applications through your browser: clicks there have an unpredictable behavior! sometimes they work, sometimes they are misplaced, sometimes they don’t do anything!

    The awesomium.dll I gave you the link to is the princeofcode one, version 1.08, unchanged. But if you would like the source codes + some improvements done by others, I found this nice link http://github.com/pathorn/awesomium. IT is the latest 1.08 version in open source with some other contributions – I did not test it but maybe it can help you

    Good luck!

    Reply

  72. Also (sorry to post so many stuff!!), a lot of people on the blog asked if the scrollbars can be replaced by WPF scrollview. As you said it is not directly accessible but there is a workaround:

    If you navigate to the page you want to show in invisible mode, then get the lenght of the page with Javascript, you can then pass the lenght of the content to WPF with ExecuteJavaScriptwithResults… This should allow you to put scrollview on the container with the proper proportions…
    I am trying that today, and will report how it works!

    Reply

  73. Hi,
    I tried to do things with Callback and ExecuteJavascript (and with result) but nothing is called, anyone got a working sample ? it would be so appreciated 🙂
    Note : I tried with code from Chris Cavanagh // October 9, 2009 at 12:28 am

    Thx

    Reply

  74. Also, I got :
    A first chance exception of type ‘System.AccessViolationException’ occurred in Cjc.AwesomiumWrapper.dll
    in Cjc.AwesomiumWrapper.h
    ” String^ GetContentAsText( int maxChars )
    {
    std::wstring result;
    webView->getContentAsText( result, maxChars );
    return marshalString( result );
    }

    Source code is :
    MessageBox.Show(_browser.GetContentAsText(100));

    Nothing really special but it doesn’t work (I am with full trust and WPF).

    Any idea ? :/

    Reply

    1. machito – I’ll take a look at the issues you mentioned. Awesomium/Chromium always renders with anti-aliasing, and the WebBrowser control only has that output to work with.

      Which OS are you running and which DPI is your display set to? If you’re on Windows 7 you might be at 120 DPI (instead of the 96 XP or Vista would default to). I’ll shortly be posting a small fix to the WebBrowser to better handle different DPI settings. Currently if you’re at 120 DPI the browser content will be stretched (because it’s hard-coded to render at 96 DPI internally) and will look blurry.

      Reply

  75. Hi chris,
    I have successfully integrate the browser component control (Awesomium.dll,icudt38.dll,Cjc.ChromiumBrowser.dll,Cjc.AwesomiumWrapper.dll) in my application, and in general it works on my development pc with Visual Studio 2008 installed. The problem came up when i try to run my application at user’s machine with no VS2008 installed. The machine already installed with .NET 3.5 sp1 framework and C++ runtime and I put all the the dlls (Awesomium.dll,icudt38.dll,Cjc.ChromiumBrowser.dll,Cjc.AwesomiumWrapper.dll) in the same directory with my application .exe files.
    When i runs the app, the app crash, the error is something like this..
    EventType : clr20r3 P1 : wpfTestbrowser.exe P2 : 1.0.0.0 P3 : 4b590617
    P4 : presentationframework P5 : 3.0.0.0 P6 : 4938d608 P7 : 625a
    P8 : e1 P9 : system.windows.markup.xamlparse

    Anybody have successfully runs this component to the machine without Visual studio?

    Reply

    1. sitinotliza – A few ideas/thoughts:

      1) Does the ClickOnce demo I published work on the user’s machine?
      2) Make sure all assemblies are release builds and target x86 (if appropriate / available).
      3) Are both your machine and user machines on a 32bit OS, or is one of them 64?
      4) Try adding an UnhandledExceptioon handler to your app and see if you can capture the exception…

      Hope this helps!

      Reply

      1. Hi Chris,
        Thanks for tips. I’m now solve my problems. Tips number 4, helps me a lot. I can easily debugging by adding try and catch at the component Initialization method. At the client machine, the apps failed to load a method inside the Cjc.AwesomiumWrapper.dll. After a few try and guessing, i found out that my Awesomium.dll in the client machine is not the latest one as the size of the dll is different. Maybe I wrongly copied from the older version.
        After replacing the file with the latest one, the app is now working at the user machine.
        Again, thanks for the tips.

      2. Yeah, the working one is 9.62 MB in size. The crash one is 8.36 MB. I’m not sure which one is Awesomium 1.5. But in my case, the working one (in users machine) is the file with 9.62 MB in size. Any clue which version is it?

      3. Chris – In design time the browser cannot render in Visual Studio designer with the following error:
        Could not create an instance of type ‘WebBrowser’

        But, i just ignore it because i still can successfully rebuilt my solution. Is there any way to get rid of this problem? Or there is something to configure…

      4. sitinotliza – It might just be that VS can’t find the Awesomium_d.dll assembly in its search locations. It could also be a silly bug in my WebBrowser control 🙂 I’ll take a look at it ASAP.

  76. Hi chris,
    I have successfully integrate the browser component control (Awesomium.dll,icudt38.dll,Cjc.ChromiumBrowser.dll,Cjc.AwesomiumWrapper.dll) in my application, and in general it works on my development pc with Visual Studio 2008 installed. The problem came up when i try to run my application at user’s machine with no VS2008 installed. The machine already installed with .NET 3.5 sp1 framework and C++ runtime and I put all the the dlls (Awesomium.dll,icudt38.dll,Cjc.ChromiumBrowser.dll,Cjc.AwesomiumWrapper.dll) in the same directory with my application .exe files.
    When i runs the app, the app crash, the error is something like this..
    EventType : clr20r3 P1 : wpfTestbrowser.exe P2 : 1.0.0.0 P3 : 4b590617
    P4 : presentationframework P5 : 3.0.0.0 P6 : 4938d608 P7 : 625a
    P8 : e1 P9 : system.windows.markup.xamlparse

    Anybody have successfully runs this component to the machine without Visual studio?

    Reply

  77. Hi chris,
    I have successfully integrate the browser component control (Awesomium.dll,icudt38.dll,Cjc.ChromiumBrowser.dll,Cjc.AwesomiumWrapper.dll) in my application, and in general it works on my development pc with Visual Studio 2008 installed. The problem came up when i try to run my application at user’s machine with no VS2008 installed. The machine already installed with .NET 3.5 sp1 framework and C++ runtime and I put all the the dlls (Awesomium.dll,icudt38.dll,Cjc.ChromiumBrowser.dll,Cjc.AwesomiumWrapper.dll) in the same directory with my application .exe files.
    When i runs the app, the app crash, the error is something like this..
    EventType : clr20r3 P1 : wpfTestbrowser.exe P2 : 1.0.0.0 P3 : 4b590617
    P4 : presentationframework P5 : 3.0.0.0 P6 : 4938d608 P7 : 625a
    P8 : e1 P9 : system.windows.markup.xamlparse

    Anybody have successfully runs this component to the machine without Visual studio?

    please help to solve this issue

    Reply

  78. hey chris thanks for such a wonderful project
    just one thing i want to ask i am a beginner so i want to ask that how to call WPF chromium from another projet by just clicking on a button…

    thanks in advance

    Reply

  79. Hi,
    Cool what you did. I am completely new here, but when I open a normal webbrowser the cpu is at 0%, when i open the same link in the example it runs continiously at 10%.

    is this because each interval a photo is taken from the webbrowser content???

    Reply

    1. photoShooter – Does it behave the same for every site? (even ones with static content / no flash etc?). Apparently there’s a bug in .NET 3.5’s WriteableBitmap that can cause it to render the entire bitmap instead of just the “dirty” area; it’s been fixed in .NET 4, so it might be interesting to compare with a machine running the newer framework…

      Reply

  80. Yes, it does behave the same when looking at the performance.
    (I tried http://www.google.com and a heavy site with lots of crap….) This is on a 3.5 machine

    On a framework 4.0 machine it does not refresh anymore. after a resize it shows the latest image.

    Reply

  81. Hi Chris,

    Your awesomium browser cannot click at html textbox. but if your right-click, then its ok. Strange bug…

    Reply

      1. Same problem over here, with dll’s from ClickOnce demo, and it occurs on all sites. I have to right-click to enter an input box. I’m using Visual Studio 2008 on a 64-bit Windows 7 box.

        Very cool control, by the way 😉

    1. SitiIsLiza / Diederik – Might be something I’ve messed up for 64bit… Do you have a 32bit OS you can test for same issue on? Also, if you build WebBrowser from source, do you get the same problem?

      Reply

      1. Hello, i have same issue. I have to use right-click to enter in input boxes.
        I’m using dlls from “Cjc.ChromiumBrowserDemo.zip”, vs2010(vb.net), framework 4.0 and windows 7 32bit.
        I have no issues running your “Cjc.ThreeDeemium.exe”.
        Strange problem, anyway compliment for your work.

      2. Well, i found the solution using ScrollViewer control.
        Just override “OnMouseLeftButtonDown” without calling “base.OnMouseLeftButtonDown”.

  82. Wonderful work, Chris! Congratulations!

    I just ran the WebSnapshot project from VS 2008 and I found out a bug in the RenderSnapshot method.

    Instead of

    using (var webCore = new CAW.WebCore())

    you should have

    var userAgentOverride = “Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.249.89 Safari/532.5”;

    using (var webCore = new CAW.WebCore(“”, userAgentOverride))

    Don’t ask me why 😀

    Reply

    1. Helder – Thanks for that! I’d only recently added the user agent override stuff; perhaps I broke something? 🙂 What happens if you don’t override it? (should use Awesomium’s default, but possible I overlooked it).

      Reply

      1. If I don’t override it, I get this:

        System.IndexOutOfRangeException was unhandled
        Message=”Index was outside the bounds of the array.”
        Source=”Cjc.AwesomiumWrapper”
        StackTrace:
        at clix.detail.StringMarshaler.marshal(basic_string<char\,std::char_traits\,std::allocator >* , String string) in c:\somepath\wpfchromium-43040\cjc.awesomiumwrapper\clix.h:line 136
        at clix.marshalString(basic_string<char\,std::char_traits\,std::allocator >* , String string) in c:\somepath\wpfchromium-43040\cjc.awesomiumwrapper\clix.h:line 188
        at CjcAwesomiumWrapper.WebCore.Initialize(String cachePath, String cookiePath, String pluginPath, String logPath, LogLevel level, Boolean enablePlugins, PixelFormat pixelFormat, String userAgentOverride) in c:\somepath\wpfchromium-43040\cjc.awesomiumwrapper\cjc.awesomiumwrapper.h:line 611
        at CjcAwesomiumWrapper.WebCore..ctor() in c:\somepath\wpfchromium-43040\cjc.awesomiumwrapper\cjc.awesomiumwrapper.h:line 618
        at Cjc.WebSnapshot.Program.RenderSnapshot(String url, Byte[] buffer, Int32 width, Int32 height, Boolean transparent) in C:\somepath\wpfchromium-43040\Cjc.WebSnapshot\Program.cs:line 58
        at Cjc.WebSnapshot.Program.Main(String[] args) in C:\somepath\wpfchromium-43040\Cjc.WebSnapshot\Program.cs:line 38
        at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
        at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
        at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
        at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
        at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
        at System.Threading.ThreadHelper.ThreadStart()

  83. hi chris,
    i need to read the content as text. The method getContentAsText take infinite time and never returns. Can you please help. Is there any other way to get the content of the body of the webpage that is currently loaded.

    Reply

    1. Miguel – You can do this with the CreateObject and SetObjectCallback methods on the WebBrowser control. Let me know if you need more detail and I’ll put together a sample for you (probably as part of the next release, once I get some bugs ironed out).

      Reply

  84. Hi Chris

    thanks it seems to work. For people that are interested here is what I did:

    browser.CreateObject(“CommObject”);
    browser.SetObjectCallback(“CommObject”,”foo”);
    browser.Callback += new EventHandler(browser_Callback);

    From js, I can now call :
    CommObject.foo()

    This will call my delegate browser_Callback.

    Very cool!

    Now the question is : is there a way to return a value back to the JS ?

    thanks

    thax

    Reply

    1. Miguel – Thanks for posting that 🙂 Unfortunately the only way to get a value back to the js would be through another call (so your handler would call WebBrowser.ExecuteJavascript). It’s less convenient, but at least it’s asynchronous (ie, page doesn’t have to wait for the response, but it can if it wants to) 🙂

      Reply

  85. Thanks for this great app – I got it working on the MS Surface Table – Any ideas on how I can apply zooming functionality to the browser – have it work like IE zooming works?

    Thanks

    Reply

    1. rr – Awesomium already exposes basic ZoomIn and ZoomOut methods, and they’ll be accessible in the next version of the WebBrowser control (coming pretty soon). Unfortunately it doesn’t appear to allow control of the amount or location of the zoom (so pinch to zoom would be tricky to implement well). We should put a feature request on the Khrona/Awesomium support forum and see if they can beef it up for the next release 🙂

      Reply

  86. Thanks for that info – I guess I will work with the next version of the WebBrowser control – when it comes out – I will put a request on on the Awesomium forum in the meanwhile

    Reply

  87. Hi, I try to get the real size of web page like this : JSValue jsValue = webBrowser.ExecuteJavascriptWithResult(“document.body.clientWidth”,””);
    But it doesn’t work. Do you have an idea to resolve this problem ?
    Thanks

    Reply

  88. Tito – I’ve not tried that, but it’s an interesting idea! What value do you get back? Have you tried calling some other JS methods/code to confirm it’s otherwise working?

    Reply

    1. Hi Chris,

      Calling some other JS methods don’t work, for example I try JSValue jsValue = webBrowser.ExecuteJavascriptWithResult(“document.title”,””); or JSValue jsValue = webBrowser.ExecuteJavascriptWithResult(“location.href”,””); and that doesn’t work.
      How can I get the real size of the web page? Do you have an idea ?
      In each case, jsValue.Value() is null.
      Can I access to DOM of HTML page differently?
      Thanks

      Reply

      1. Tito – I’ll take a closer look. Are you using the VS2008 version of the source (and Awesomium 1.5.1) or the new [beta] VS2010 / Awesomium 1.6 stuff?

    1. Tito – There’s a problem in the 1.6-based version where it’s not handling JSValue correctly (so you’ll probably have more luck with the 1.5.1-based stuff currently). I’ve made some fixes (not published yet), but there’s still an issue with executeJavascriptWithResult returning nulls. As a temporary workaround it might be possible to set up a callback and get the value asynchronously (http://www.khrona.com/forum/viewtopic.php?f=6&t=47). I’ll update here when it’s fixed.

      Reply

  89. I am getting the following error when I invoke the webBrowser Conrol:
    “This Visual cannot transform the given point”
    At the following line of code:
    Loaded += delegate { address.Focus(); };

    Any suggestions as to what can be causing it?
    Here is some of the stack Trace that I get:

    Source=PresentationCore
    StackTrace:
    at System.Windows.Media.Visual.PointFromScreen(Point point)
    at Microsoft.Surface.Presentation.Controls.Primitives.KeyboardClientAdapter.GetTransformedScreenRect(Rect targetRect, Visual visual, Point screenOrigin)
    at Microsoft.Surface.Presentation.Controls.Primitives.KeyboardClientAdapter.AdjustForCollision(Rect targetRect, Visual visual, Rect bounds, Vector incrementLeft)
    at Microsoft.Surface.Presentation.Controls.Primitives.KeyboardClientAdapter.CalculateKeyboardPosition()
    at Microsoft.Surface.Presentation.Controls.Primitives.KeyboardClientAdapter.UpdateKeyboard()
    at Microsoft.Surface.Presentation.Controls.Primitives.KeyboardClientAdapter.OnGotKeyboardFocus()
    at Microsoft.Surface.Presentation.Controls.TextBoxAdapter.OnGotKeyboardFocus()
    at Microsoft.Surface.Presentation.Controls.Primitives.KeyboardClientAdapter.OnDependencyPropertyChanged(DependencyPropertyChangedEventArgs e)
    at Microsoft.Surface.Presentation.Controls.TextBoxAdapter.OnDependencyPropertyChanged(DependencyPropertyChangedEventArgs e)
    at Microsoft.Surface.Presentation.Controls.SurfaceTextBox.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
    at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
    at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, OperationType operationType)
    at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, OperationType operationType, Boolean isInternal)
    at System.Windows.DependencyObject.SetValue(DependencyPropertyKey key, Object value)
    at System.Windows.DependencyObject.SetValue(DependencyPropertyKey dp, Boolean value)
    at System.Windows.ReverseInheritProperty.FirePropertyChangeInAncestry(DependencyObject element, Boolean oldValue, DeferredElementTreeState treeState)
    at System.Windows.ReverseInheritProperty.OnOriginValueChanged(DependencyObject oldOrigin, DependencyObject newOrigin, DeferredElementTreeState& oldTreeState)
    at System.Windows.Input.KeyboardDevice.ChangeFocus(DependencyObject focus, Int32 timestamp)
    at System.Windows.Input.KeyboardDevice.TryChangeFocus(DependencyObject newFocus, IKeyboardInputProvider keyboardInputProvider, Boolean askOld, Boolean askNew, Boolean forceToNullIfFailed)
    at System.Windows.Input.KeyboardDevice.Focus(DependencyObject focus, Boolean askOld, Boolean askNew)
    at System.Windows.Input.KeyboardDevice.Focus(IInputElement element)
    at System.Windows.UIElement.Focus()

    Reply

  90. Thanks, just another question, I brought over my VS 2008 project to VS2010 – I had wrapped your stuff in a SurfaceUserControl dll – When it tries to access the cjc.ChromiumBrowser.dll it crashes bec. it can’t find it – does it matter that it is VS2010 – Would you have a VS2010 version?
    Thanks

    Reply

    1. rr – It should be able to find the .NET assemblies fine (ChromiumBrowser, AwesomiumWrapper etc) but AwesomiumWrapper also has a dependency on the Awesomium DLLs, which need to be in the same folder…

      There’s a VS2010 version available (http://wpfchromium.codeplex.com/releases/view/49484) – but it’s very much a beta, based on a more recent version of Awesomium (also a beta). It might be good for comparison / reference though 🙂

      Reply

  91. Hello Chris! I’m french so i apologize for my mistakes! I’m trying to navigate to a page with Javascript but it doesn’t work. Should I put something in my code to “annonce” there will be Javascript? Thanks

    Reply

    1. Anne-Sophie – Are you using the current WebBrowser version (with Awesomium 1.5.1) or the beta from Codeplex? (based on Awesomium 1.6 beta). Currently Awesomium 1.6’s ExecuteJavascriptWithResult method doesn’t work, although I think the regular ExecuteJavascript is ok…

      Could you send me an example of the javascript you’re calling?

      Reply

      1. Sorry I had made a mistake, everything is fine now, execpt in my page there is a but I can’t write inside.
        Is that normal? What can I do?

  92. Hi, everybody!

    I am working with changeset 43040 and I migrated it to VS 2010. Visual Studio automatically set the target .NET framework of my WPF Chromium-related projects to 4.0, including the AwesomiumWrapper project. Everything compiled, however, when running my app, it crashed with the error below (in post-scriptum).

    I then changed the target framework of the AwesomiumWrapper project to 3.5 as well as the other projects (I also had to install VS 2008 in order to successfully compile AwesomiumWrapper) and everything compiled and ran fine!

    My question is: is there any compilation flag that I must set in order to successfully run AwesomiumWrapper with .NET 4.0? I don’t want to have VS 2010 + VS 2008 on my dev environment…

    Thanks!

    Helder

    P.S.: Here is the runtime error (I ommitted some irrelevant info):

    Message=The invocation of the constructor on type ‘Cjc.ChromiumBrowser.WebBrowser’ that matches the specified binding constraints threw an exception.

    InnerException: System.TypeInitializationException
    Message=The type initializer for ‘Cjc.ChromiumBrowser.WebBrowser’ threw an exception.
    Source=Cjc.ChromiumBrowser
    StackTrace:
    at Cjc.ChromiumBrowser.WebBrowser..ctor()
    InnerException: System.AccessViolationException
    Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
    Source=Cjc.AwesomiumWrapper
    StackTrace:
    at Awesomium.WebCore.{ctor}(WebCore* , basic_string<wchar_t\,std::char_traits\,std::allocator >* , basic_string<wchar_t\,std::char_traits\,std::allocator >* , basic_string<wchar_t\,std::char_traits\,std::allocator >* , basic_string<wchar_t\,std::char_traits\,std::allocator >* , LogLevel , Boolean , PixelFormat , basic_string<char\,std::char_traits\,std::allocator >* )
    at CjcAwesomiumWrapper.WebCore.Initialize(String cachePath, String cookiePath, String pluginPath, String logPath, LogLevel level, Boolean enablePlugins, PixelFormat pixelFormat, String userAgentOverride)

    Reply

      1. Gigio,

        Thank you for your reply. I’ve just followed your advice, by configuring useLegacyV2RuntimeActivationPolicy=true, but still getting the same runtime error.

  93. Helder & Gigio – The main issue is Chromium itself isn’t yet compatible with VS2010 (I’m assuming specifically the V90 C/C++ toolset). Until that happens, Awesomium can only be used with VS2008/v90. However, it should still be possible to compile Cjc.AwesomiumWrapper as a .NET 3.5 (v90) project in VS2010 (that’s what I’ve done). Everything upstream can be .NET4.

    When Awesomium 1.6 releases (still beta currently) I’ll get this stuff updated, hopefully removing some of the confusion/mess 🙂

    Hope this helps!

    Reply

  94. Using Visual Studio 2010 I make sure the properties of Cjc.AwesomiumWrapper -> Configuration Properties -> General -> Platform Toolset is v90.
    Then I get the following error:
    error MSB8009: .NET Framework 2.0/3.0/3.5 target the v90 platform toolset. Please make sure that Visual Studio 2008 is installed on the machine.

    How to get rid of that without installing Visual Studio 2008 ?

    Reply

    1. Koichi,

      I was also looking for an alternative solution, by installing Windows SDK for .NET Framework 3.5, but with no success. I eventually had to install VS 2008. I don’t know if its possible to only install Windows SDKs for Visual Studio 2008 (without the IDE).. This could be an alternative to a full VS 2008 installation, but I think its simpler to just install VS 2008 🙂

      Reply

    1. Hi, Koichi.

      I tried Win SDK for Win7 + .NET 3.5 SP1 but it didn’t work.

      Visual Studio 2008 SDK is targeted for developing VS extensions.

      I am afraid you have no better option than installing VS 2008 😦

      Helder

      Reply

  95. Hi Chris, sorry for bother you, but i’m having problems to run Cjc.ChromiumBrowserDemo. Is the know System.IO.FileNotFoundException
    Could not load file or assembly ‘Cjc.AwesomiumWrapper.dll’ or one of its dependencies.
    I try to do a new project and references AwesomiumWrapper.dll and ChromiumBrowser.dll and throw exactly the same error.
    The build in boths cases don’t fail, only fail at the IDE whe you try to display MainWindow.xaml, or when you try to run the project.
    Can you help me with this issue?
    Thanks in advance

    Reply

  96. Hi Chris, sorry for bother you, but i’m having problems to run Cjc.ChromiumBrowserDemo. Is the know

    System.IO.FileNotFoundException
    Could not load file or assembly ‘Cjc.AwesomiumWrapper.dll’ or one of its dependencies.

    I try to do a new project and references AwesomiumWrapper.dll and ChromiumBrowser.dll and throw exactly the same error.

    The build project in boths cases doesn’t fail (Build Succed), only fail at the IDE when you try to display MainWindow.xaml, or when you try to run the project.
    Can you help me with this issue?

    Thanks in advance

    Reply

    1. Alejandro, the FileNotFoundException explains it all.
      You should follow the instructions to have all your compiled binaries in the same folder as the required dependencies.
      I suggest you to compare your new project structure with the structure of the original ChromiumBrowserDemo project.
      Also, take your time to read the instructions from this blog post and the one of the fourth version of the project at https://chriscavanagh.wordpress.com/2010/10/04/a-real-net-4-0-webbrowser/

      Reply

    2. Alejandro – Let me know if you hit any other issues. The folder structure stuff is kind of a pain; even more so if you want to get the WebBrowser to behave in the VS designer (if anyone gets chance to figure that out, would be useful to post here 🙂 ).

      Reply

  97. Hi, Chris

    After downloading the source code project (not .net 4.0 version ), I tried to open the solution with vs2008 and encountered errors as follows:

    unable to read the project file ‘Cjc.ThreeDeemium.csprojc’:
    D:\MyVsProjects\…\WpfChromium\Cjc.ThreeDeemium\Cjc.ThreeDeemium.csproj: The toos version “4.0” is unrecognized.

    the other four projects were probably loaded, so why comes the 4.0 here? Isn’t this solution built for .net 3.5?

    Reply

    1. vicky – I’ll look into this and update the project. Until then, here’s a few things to try:

      1) Try editing the .csproj’s in Notepad and change the ToolsVersion value to 3.5.
      2) Create a new .NET 3.5 WPF project and add the source files from Cjc.ThreeDeemium. You’llneed a project or binary reference to Cjc.ChromiumBrowser, and possibly Cjc.AwesomiumWrapper. Make sure the Awesomium binaries get copied to your output folder (a post-build step might be easiest).

      Hope this helps!

      Reply

  98. Hi Chris,

    I’m using the latest WPF Chromium 4.0 with Awesomium 1.6 RC1.

    Apparently when using flash 10 (didn’t tried it with other versions of flash) When a popup comes out of the flash it is not reachable and cannot be clicked.

    For example, surfing to http://www.chatroulette.com/ (Really for developing purposes only 🙂 ),
    You get a popup asking you to allow flash to integrate with your webcam. But in WPFChromium this popup is just not clickable. It responds to TAB but I can’t click “ENTER” on my selection.

    Screenshot:

    Any thoughts?

    Thanks!!!

    Reply

  99. Hi Chris Cavanagh,
    how to use wpf-chromium-webbrowser on samsung sur40 (x64 bit win 7 os) machine?

    Thanks in advance..

    Reply

Leave a reply to Tito Cancel reply