Evaluate Java Script in CefSharp 3

1,953 views
Skip to first unread message

Clemens Hoffmann

unread,
Oct 21, 2014, 8:42:23 AM10/21/14
to cefs...@googlegroups.com
Hello,
We have an application that is using CefSharp 1..
This application loads a Java Scriptfile using EvaluateScrip(...).
Later the application calls functions in the Java script library.
The application uses WPF and a CustomControl that wraps the WebView control.
The wrapper fakes a rectabgle for the designer and adds an IScrollInfo implementation.
This all works fine.

Now I am porting this to CefSharp 3.
I manged to create a UserControll and add the IScrollInfo functionality.
But I did not manage to call any Java script function.
Since we use a ScrollViewer I hide the CEF scrollbars. This is done with a Java script function: @"document.documentElement.style.overflow = ""hidden"";"
This works with CEFSharp 1 but not with CEFSharp 3
When calling ChromiumWebBrowser >> EvaluateScript(...) I get the error

There was no end point listening at net.pipe://localhost/CefSharpSubProcessProxy/10920/1 that could accept the message.
This is often caused by an incorrect address or SOAP action. For more details, see "InnerException", if it exists.

Inner Exception: The pipe end point net.pipe://localhost/CefSharpSubProcessProxy/10920/1 was not found on the local computer.

I added my code below.
I am not shure if I did miss something. Any Hint?
greetings
      Clemens Hoffmann

Code hier eingeben...

        public CefSharp3ControlWrapper()
        {
            InitializeComponent();
            if (DesignerProperties.GetIsInDesignMode(this))
            {
                InDesignMode = true;
                System.Windows.Shapes.Rectangle rect = new System.Windows.Shapes.Rectangle();
                rect.Fill = System.Windows.Media.Brushes.LightGray;
                this.WebViewWrapper.Children.Add(rect);
                Label text = new Label();
                text.Content = "Cef Sharp Control";
                text.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                text.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                this.WebViewWrapper.Children.Add(text);
            }
            else
            {
                this.InitializeCEF();
                InDesignMode = false;
                web = new ChromiumWebBrowser();
                web.Name = "WebView";
 
                web.FrameLoadEnd -= new EventHandler<CefSharp.FrameLoadEndEventArgs>(webView_LoadCompleted);
                web.FrameLoadEnd += new EventHandler<CefSharp.FrameLoadEndEventArgs>(webView_LoadCompleted);
                web.IsBrowserInitializedChanged -= new DependencyPropertyChangedEventHandler(webView_Initialized);
                web.IsBrowserInitializedChanged += new DependencyPropertyChangedEventHandler(webView_Initialized);
 
                web.SnapsToDevicePixels = true;
                web.UseLayoutRounding = true;
                web.Address = "about:blank";
 
                this.WebViewWrapper.Children.Add(web);
                this.LoadJavaScript = true;
            }
        }
 
        /// <summary>
        /// Before anything can be done with the web control we need to initialize the core
        /// </summary>
        private void InitializeCEF()
        {
            var settings = new CefSettings
            {
                BrowserSubprocessPath = "CefSharp.BrowserSubprocess.exe"
            };
 
            Cef.Initialize(settings);
        }
 
        /// <summary>
        /// The browser is initialized. Inform components that wait for it.
        /// </summary>
        /// <param name="sender">The web view</param>
        /// <param name="e">the changed event</param>
        private void webView_Initialized(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (this.web.IsBrowserInitialized)
                this.web.EvaluateScript(@"document.documentElement.style.overflow = ""hidden"";");
 
            EventHandler evt = Volatile.Read(ref this.IsBrowserInitializedChanged);
            if (evt != null)
                evt(thisEventArgs.Empty);
        }


Clemens Hoffmann

unread,
Oct 23, 2014, 5:26:51 AM10/23/14
to cefs...@googlegroups.com
Hello,
I just
- downloaded the current master
- compiled it
- run the "CefSharp.Wpf.Example"
- load another web site (i.e: www.heise.de).
- typed "document.documentElement.style.overflow = "hidden" " into the Execute Javascript (synchronously) and run it.

I get the same error as in my application.
Thus I guess there is something broken.

It worked in CefSharp 1.
gretings
     Clemens Hoffmann

Jørn Hansen

unread,
Oct 24, 2014, 3:03:34 AM10/24/14
to cefs...@googlegroups.com
Yep, sounds like you are right. I can reproduce it with my current x86/Release build of the WPF example :-(
It seems to happens on some sites only. I looked up style.overflow https://developer.mozilla.org/en-US/docs/Web/CSS/overflow ... could it be that CEF simply crashes on us? - should be verifiable via `cefclient.exe` from the CEF project + DevTools on that http://heise.de site + debug.log

Could you please report the issue in the GitHub repo so we make sure to fix it. (And I hope my quick scribbles above leads you onto something)

Best regards,
JornH

Jørn Hansen

unread,
Oct 24, 2014, 11:02:45 AM10/24/14
to cefs...@googlegroups.com
Hello Clemens,

OK, forget about my previous post ... it works for me with the `JsBinding_WIP` branch.

Note the signature of the method has changed into an Async method returning a Task.

If you want is as a NuGet package currently use the latest `-Pre` package, right now it's  https://www.nuget.org/packages/CefSharp.Wpf/33.1.0-pre01


Best regards,
JornH


On Thursday, October 23, 2014 11:26:51 AM UTC+2, Clemens Hoffmann wrote:
Reply all
Reply to author
Forward
0 new messages