private WebBrowserTab AddNewBrowser(FATabStripItem tabStrip, String url) { if (url == "") { url = NewTabURL; } ChromiumWebBrowser browser = new ChromiumWebBrowser(url); // set config ConfigureBrowser(browser); // set layout browser.Dock = DockStyle.Fill; tabStrip.Controls.Add(browser); browser.BringToFront(); // add events browser.StatusMessage += Browser_StatusMessage; browser.LoadingStateChanged += Browser_LoadingStateChanged; browser.TitleChanged += Browser_TitleChanged; browser.LoadError += Browser_LoadError; browser.AddressChanged += Browser_URLChanged; browser.DownloadHandler = dHandler; browser.MenuHandler = mHandler; browser.LifeSpanHandler = lHandler; browser.KeyboardHandler = kHandler; browser.RequestHandler = rHandler; // new tab obj WebBrowserTab tab = new WebBrowserTab { IsOpen = true, Browser = browser, Tab = tabStrip, OrigURL = url, CurURL = url, Title = "New Tab", DateCreated = DateTime.Now }; // save tab obj in tabstrip tabStrip.Tag = tab; if (url.StartsWith("WebBrowserDemo:")) { CefSharpSettings.LegacyJavascriptBindingEnabled = true; CefSharp.BindingOptions option = new CefSharp.BindingOptions(); browser.RegisterAsyncJsObject("host", host, option); } return(tab); }
private void Form1_Load(object sender, EventArgs e) { var browser = new ChromiumWebBrowser(String.Empty) { Dock = DockStyle.Fill, BrowserSettings = new BrowserSettings { FileAccessFromFileUrls = CefState.Enabled, UniversalAccessFromFileUrls = CefState.Enabled, Javascript = CefState.Enabled, ImageLoading = CefState.Enabled, JavascriptAccessClipboard = CefState.Enabled, JavascriptCloseWindows = CefState.Enabled, JavascriptDomPaste = CefState.Enabled } }; browser.RequestContext = new RequestContext(new RequestContextHandler()); browser.LoadingStateChanged += OnLoadingStateChanged; browser.IsBrowserInitializedChanged += Browser_IsBrowserInitializedChanged; panel1.Controls.Add(browser); Browser = browser; browser.LoadHtml("<html><body>Wait Login...\n<script>\n callbackObj.LoginWebFrame(\"aaa\");\n</script>\n</body></html>"); var bindScriptOption = new CefSharp.BindingOptions(); //bindScriptOption.CamelCaseJavascriptNames = false; browser.Load(home_url); //browser.MenuHandler = new MenuHandler(); //browser.RequestHandler = new WinFormsRequestHandler(openNewTab); //browser.JsDialogHandler = new JsDialogHandler(); //browser.DownloadHandler = new MyDownLoadFile(); //browser.RequestHandler = new MyRequestHandler(); Browser.FrameLoadStart += (sender0, e0) => { var uri = new Uri(e0.Url); this.toolStripStatusLabel1.Text = uri.ToString() + " loading"; }; Browser.FrameLoadEnd += (sender0, e0) => { var uri = new Uri(e0.Url); this.toolStripStatusLabel1.Text = uri.ToString() + " "; }; }
/// <summary> /// <para>Asynchronously registers a Javascript object in this specific browser instance.</para> /// <para>Only methods of the object will be availabe.</para> /// </summary> /// <param name="webBrowser">The browser to perform the registering on</param> /// <param name="name">The name of the object. (e.g. "foo", if you want the object to be accessible as window.foo).</param> /// <param name="objectToBind">The object to be made accessible to Javascript.</param> /// <param name="options">binding options - camelCaseJavascriptNames default to true </param> /// <exception cref="Exception">Browser is already initialized. RegisterJsObject must be + /// called before the underlying CEF browser is created.</exception> /// <remarks>The registered methods can only be called in an async way, they will all return immeditaly and the resulting /// object will be a standard javascript Promise object which is usable to wait for completion or failure.</remarks> public static void RegisterAsyncJsObject(this IWebBrowser webBrowser, string name, object objectToBind, BindingOptions options = null) { webBrowser.ValidateBrowserBeforeRegistering(); webBrowser.JavascriptObjectRepository.Register(name, objectToBind, true, options); }
public static void RegisterAsyncJsObject(this IWebBrowser webBrowser, string name, object objectToBind, BindingOptions options = null) { throw new NotImplementedException("This method has been removed, see https://github.com/cefsharp/CefSharp/issues/2990 for details on migrating your code."); }
/// <summary> /// Registers a Javascript object in this specific browser instance. /// </summary> /// <param name="webBrowser">The browser to perform the registering on</param> /// <param name="name">The name of the object. (e.g. "foo", if you want the object to be accessible as window.foo).</param> /// <param name="objectToBind">The object to be made accessible to Javascript.</param> /// <param name="options">binding options - camelCaseJavascriptNames default to true </param> /// <exception cref="Exception">Browser is already initialized. RegisterJsObject must be + /// called before the underlying CEF browser is created.</exception> public static void RegisterJsObject(this IWebBrowser webBrowser, string name, object objectToBind, BindingOptions options = null) { CefSharpSettings.WcfEnabled = true; webBrowser.ValidateBrowserBeforeRegistering(); webBrowser.JavascriptObjectRepository.Register(name, objectToBind, false, options); }