JS code in WebBrowserFrameLoadEnded

Having problems with building or using the CefSharp .NET binding? Ask your CEF-related questions here. Please ask general usage questions on StackOverflow.

Moderator: amaitland

JS code in WebBrowserFrameLoadEnded

Postby Maksimmkv » Wed Sep 29, 2021 9:47 am

Hi everyone.
Open the URL in a new tab. Running script
Code: Select all
public BrowserMain(string address, bool newtabrequest)
        {
            InitializeComponent(); 
            .....
            WebBrowser.FrameLoadEnd += WebBrowserFrameLoadEnded;
}
       private void WebBrowserFrameLoadEnded(object sender, FrameLoadEndEventArgs e)
       {
            if (e.Frame.IsMain)
            {
             WebBrowser.ExecuteScriptAsync("document.querySelectorAll('#ui > ul > li:nth-child(1) > div').forEach(function(i){ i.click()})" + ";");
            }
       }
,

waiting for script to run. But it happens that the application simply closes without errors. How do I run the script correctly after loading the page? Thank you
Maksimmkv
Newbie
 
Posts: 7
Joined: Tue Aug 03, 2021 2:19 pm

Re: JS code in WebBrowserFrameLoadEnded

Postby amaitland » Wed Sep 29, 2021 2:09 pm

What version are you using?

On the surface your code looks ok, try something simpler like changing the background colour.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am

Re: JS code in WebBrowserFrameLoadEnded

Postby Maksimmkv » Sat Oct 02, 2021 12:15 pm

amaitland wrote:What version are you using?

On the surface your code looks ok, try something simpler like changing the background colour.


90.6.50 CefSharp WinForms

Thank you, when executing any script - the application closes ((
Maksimmkv
Newbie
 
Posts: 7
Joined: Tue Aug 03, 2021 2:19 pm

Re: JS code in WebBrowserFrameLoadEnded

Postby amaitland » Sat Oct 02, 2021 2:11 pm

If you can reproduce the problem with version 94 then please provide a more detailed example.

Version 90 is old and unsupported.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am


Return to CefSharp Forum

Who is online

Users browsing this forum: No registered users and 16 guests