C# 严重错误:“;“浏览器尚未初始化”;何时执行;ExecuteScriptAsync“;或;EvaluateScript Async“;

C# 严重错误:“;“浏览器尚未初始化”;何时执行;ExecuteScriptAsync“;或;EvaluateScript Async“;,c#,winforms,chromium-embedded,cefsharp,C#,Winforms,Chromium Embedded,Cefsharp,我正在尝试使用CeSharp执行javascript。 最后我犯了一个错误: 浏览器尚未初始化。使用IsBrowserInitializedChanged事件并检查IsBrowserInitialized属性以确定浏览器何时已初始化 当我使用这样的:“ExecuteScriptAsync”方法时 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using

我正在尝试使用CeSharp执行javascript。 最后我犯了一个错误: 浏览器尚未初始化。使用IsBrowserInitializedChanged事件并检查IsBrowserInitialized属性以确定浏览器何时已初始化

当我使用这样的:“ExecuteScriptAsync”方法时

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CefSharp;
using CefSharp.WinForms;

namespace CefSharp
{

    public partial class Form1 : Form
    {
        public ChromiumWebBrowser chromeBrowser;


        public Form1()
        {
            InitializeComponent();
            // Start the browser after initialize global component
            InitializeChromium();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            chromeBrowser.ExecuteScriptAsync("alert('Adam')");
        }

        public void InitializeChromium()
        {
            CefSettings settings = new CefSettings
            {
                CachePath = "cache"
            };
            // Initialize cef with the provided settings
            Cef.Initialize(settings);
            // Create a browser component
            chromeBrowser = new ChromiumWebBrowser("http://localhost/Test/index.html");

            // Add it to the form and fill it to the form window.
            this.Controls.Add(chromeBrowser);
            chromeBrowser.Dock = DockStyle.Fill;
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            Cef.Shutdown();
        }
    }    
}
或者当我使用“EvaluateScript异步”


有人知道如何处理吗?

请参阅Hi@amaitland有没有办法获取文档(就像我们可以在默认的webbrowser控件上获取文档一样)?还可以检查浏览器的readyState=“completed”吗?您只能通过JavaScript访问DOM。你需要知道readystate的确切用途是什么?如果你在LoadingStateChanged中执行JavaScript,那么文档应该是readyHard,不足以继续。在执行
JavaScript
之前,需要确保浏览器已充分加载。请重新阅读我提供的链接,也许吧?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CefSharp;
using CefSharp.WinForms;

namespace CefSharp
{

    public partial class Form1 : Form
    {
        public ChromiumWebBrowser chromeBrowser;


        public Form1()
        {
            InitializeComponent();
            // Start the browser after initialize global component
            InitializeChromium();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            var task = chromeBrowser.EvaluateScriptAsync("alert('Adam')");

            task.ContinueWith(t =>
            {
                if (!t.IsFaulted)
                {
                    var response = t.Result;
                    var EvaluateJavaScriptResult = response.Success ? (response.Result ?? "null") : response.Message;
                }
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }

        public void InitializeChromium()
        {
            CefSettings settings = new CefSettings();
            // Initialize cef with the provided settings
            Cef.Initialize(settings);
            // Create a browser component
            chromeBrowser = new ChromiumWebBrowser("http://localhost/Test/index.html");

            // Add it to the form and fill it to the form window.
            this.Controls.Add(chromeBrowser);
            chromeBrowser.Dock = DockStyle.Fill;
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            Cef.Shutdown();
        }
    }    
}