public unsafe int OnConsoleMessage(cef_browser_t *browser, CefLogSeverity level, [Immutable] cef_string_t *message, [Immutable] cef_string_t *source, int line) { fixed(cef_display_handler_t *self = &this) { return(((delegate * unmanaged[Stdcall] < cef_display_handler_t *, cef_browser_t *, CefLogSeverity, cef_string_t *, cef_string_t *, int, int >)on_console_message)(self, browser, level, message, source, line)); } }
/// <summary> /// The on console message. /// </summary> /// <param name="browser"> /// The browser. /// </param> /// <param name="level"> /// The level. /// </param> /// <param name="message"> /// The message. /// </param> /// <param name="source"> /// The source. /// </param> /// <param name="line"> /// The line. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> protected override bool OnConsoleMessage(CefBrowser browser, CefLogSeverity level, string message, string source, int line) { var evntArgs = new ConsoleMessageEventArgs(message, source, line); _browser.InvokeAsyncIfPossible(() => _browser.OnConsoleMessage(evntArgs)); return(evntArgs.Handled); }
public ConsoleMessageEventArgs(CefLogSeverity level, string message, string source, int line) { Level = level; Message = message; Source = source; Line = line; }
protected override bool OnConsoleMessage(CefBrowser browser, CefLogSeverity level, string message, string source, int line) { switch (level) { case CefLogSeverity.Disable: break; case CefLogSeverity.Default: case CefLogSeverity.Info: Logger.Info($"CEF: {message}"); break; case CefLogSeverity.Warning: Logger.Warn($"CEF: {message}"); break; case CefLogSeverity.Error: case CefLogSeverity.Fatal: Logger.Error($"CEF: {message}"); break; case CefLogSeverity.Verbose: Logger.Debug($"CEF: {message}"); break; default: throw new ArgumentOutOfRangeException(nameof(level), level, null); } return(true); }
protected override bool OnConsoleMessage(CefBrowser browser, CefLogSeverity level, string message, string source, int line) { var e = new ConsoleMessageEventArgs(level, message, source, line); _core.InvokeIfRequired(() => _core.OnConsoleMessage(e)); return(e.Handled); }
static LogType ToLogType(CefLogSeverity level) { switch (level) { case CefLogSeverity.Verbose: return(LogType.Debug); case CefLogSeverity.Info: return(LogType.Message); case CefLogSeverity.Warning: return(LogType.Warning); case CefLogSeverity.Error: case CefLogSeverity.ErrorReport: return(LogType.Error); default: return(LogType.Message); } }
protected override bool OnConsoleMessage(CefBrowser browser, CefLogSeverity level, string message, string source, int line) { var m = string.Format("{0} ({1}:{2})", message, source, line); switch (level) { case CefLogSeverity.Default: case CefLogSeverity.Verbose: case CefLogSeverity.Info: Trace.TraceInformation(m); break; case CefLogSeverity.Warning: Trace.TraceWarning(m); break; case CefLogSeverity.Error: case CefLogSeverity.Fatal: Trace.TraceError(m); break; } return(base.OnConsoleMessage(browser, level, message, source, line)); }
public override bool OnConsoleMessage(CefBrowser browser, CefLogSeverity level, string message, string source, int line) { return(_implementation.OnConsoleMessage(browser, level, message, source, line)); }
/// <summary> /// Called to display a console message. Return true to stop the message from /// being output to the console. /// </summary> protected virtual bool OnConsoleMessage(CefBrowser browser, CefLogSeverity level, string message, string source, int line) { return(false); }
private int on_console_message(cef_display_handler_t *self, cef_browser_t *browser, CefLogSeverity level, cef_string_t *message, cef_string_t *source, int line) { CheckSelf(self); var mBrowser = CefBrowser.FromNative(browser); var mMessage = cef_string_t.ToString(message); var mSource = cef_string_t.ToString(source); return(OnConsoleMessage(mBrowser, level, mMessage, mSource, line) ? 1 : 0); }
protected override bool OnConsoleMessage(CefBrowser browser, CefLogSeverity level, string message, string source, int line) { Debug.Print("[{0}]: {1} ({2}, line: {3})", level, message, source, line); return(false); }
public unsafe extern int OnConsoleMessage(cef_browser_t *browser, CefLogSeverity level, [Immutable] cef_string_t *message, [Immutable] cef_string_t *source, int line);
protected override bool OnConsoleMessage(CefBrowser browser, CefLogSeverity level, string message, string source, int line) { FRenderer.Logger.Log(ToLogType(level), string.Format("{0} ({1}:{2})", message, source, line)); return(base.OnConsoleMessage(browser, level, message, source, line)); }
/// <summary> /// Starts CEF /// </summary> /// <exception cref="Exception"></exception> public void Init() { // ReSharper disable once RedundantAssignment string[] argv = args; #if LINUX //On Linux we need to do this, otherwise it will just crash, no idea why tho argv = new string[args.Length + 1]; Array.Copy(args, 0, argv, 1, args.Length); argv[0] = "-"; #endif //Set up CEF args and the CEF app CefMainArgs cefMainArgs = new CefMainArgs(argv); BrowserProcessCEFApp cefApp = new BrowserProcessCEFApp(launchArguments); //Run our sub-processes int exitCode = CefRuntime.ExecuteProcess(cefMainArgs, cefApp, IntPtr.Zero); if (exitCode != -1) { Environment.Exit(exitCode); return; } //Backup if (argv.Any(arg => arg.StartsWith("--type="))) { Environment.Exit(-2); return; } //Do we have a cache or not, if not CEF will run in "incognito" mode. string cachePathArgument = null; if (launchArguments.CachePath != null) { cachePathArgument = launchArguments.CachePath.FullName; } //Convert UnityWebBrowser log severity to CefLogSeverity CefLogSeverity logSeverity = launchArguments.LogSeverity switch { LogSeverity.Debug => CefLogSeverity.Debug, LogSeverity.Info => CefLogSeverity.Info, LogSeverity.Warn => CefLogSeverity.Warning, LogSeverity.Error => CefLogSeverity.Error, LogSeverity.Fatal => CefLogSeverity.Fatal, _ => CefLogSeverity.Default }; //Setup the CEF settings CefSettings cefSettings = new CefSettings { WindowlessRenderingEnabled = true, NoSandbox = true, LogFile = launchArguments.LogPath.FullName, CachePath = cachePathArgument, //TODO: On MacOS multi-threaded message loop isn't supported MultiThreadedMessageLoop = true, LogSeverity = logSeverity, Locale = "en-US", ExternalMessagePump = false, RemoteDebuggingPort = launchArguments.RemoteDebugging, #if LINUX //On Linux we need to tell CEF where everything is, this will assume that the working directory is where everything is! ResourcesDirPath = System.IO.Path.Combine(Environment.CurrentDirectory), LocalesDirPath = System.IO.Path.Combine(Environment.CurrentDirectory, "locales"), BrowserSubprocessPath = Environment.GetCommandLineArgs()[0] #endif }; //Init CEF CefRuntime.Initialize(cefMainArgs, cefSettings, cefApp, IntPtr.Zero); //Create a CEF window and set it to windowless CefWindowInfo cefWindowInfo = CefWindowInfo.Create(); cefWindowInfo.SetAsWindowless(IntPtr.Zero, false); //Create our CEF browser settings CefColor backgroundColor = new CefColor(launchArguments.Bca, launchArguments.Bcr, launchArguments.Bcg, launchArguments.Bcb); CefBrowserSettings cefBrowserSettings = new CefBrowserSettings { BackgroundColor = backgroundColor, JavaScript = launchArguments.JavaScript ? CefState.Enabled : CefState.Disabled, LocalStorage = CefState.Disabled }; Logger.Debug($"CEF starting with these options:" + $"\nJS: {launchArguments.JavaScript}" + $"\nBackgroundColor: {backgroundColor}" + $"\nCache Path: {cachePathArgument}" + $"\nLog Path: {launchArguments.LogPath.FullName}" + $"\nLog Severity: {launchArguments.LogSeverity}"); Logger.Info("Starting CEF client..."); //Create cef browser cefClient = new BrowserProcessCEFClient(new CefSize(launchArguments.Width, launchArguments.Height), new ProxySettings(launchArguments.ProxyUsername, launchArguments.ProxyPassword, launchArguments.ProxyEnabled)); CefBrowserHost.CreateBrowser(cefWindowInfo, cefClient, cefBrowserSettings, launchArguments.InitialUrl); cefClient.OnUrlChange += OnUrlChange; }