查看版本號,插件
chrome://plugins/
chrome://version/
加載命令啟動參數 --enable-system-flash 會加載系統默認的flash瀏覽器
procedure OnBeforeCmdLine(const processType: ustring; const commandLine: ICefCommandLine); begin commandLine.AppendSwitch('--enable-system-flash'); commandLine.AppendSwitch('--disable-web-security'); commandLine.AppendSwitch('no-proxy-server'); end; begin CefCache := 'cache'; CefLocale := 'zh-CN'; CefOnBeforeCommandLineProcessing := OnBeforeCmdLine; CefSingleProcess := False; if not CefLoadLibDefault then Exit; Application.Initialize; Application.CreateForm(TMainForm, MainForm); Application.Run; end.
其它cmdLine
procedure OnBeforeCmdLine(const processType: ustring; const commandLine: ICefCommandLine); begin //加載系統安裝的flash,使用前系統需安裝flash播放器 //commandLine.AppendSwitch('--enable-system-flash'); //允許js跨域 commandLine.AppendSwitch('--disable-web-security'); //禁用代理 //commandLine.AppendSwitch('no-proxy-server'); //不同域名不同進程 commandLine.AppendSwitch('--process-per-site'); //指定子進程渲染 //commandLine.AppendSwitchWithValue('browser-subprocess-path', 'cefsubprocess.exe'); //加載指定flash版本 commandLine.AppendSwitchWithValue('ppapi-flash-version', '21.0.0.213'); commandLine.AppendSwitchWithValue('ppapi-flash-path', 'PepperFlash\pepflashplayer.dll'); end;
拓展JS方法
TCustomRenderProcessHandler = class(TCefRenderProcessHandlerOwn) protected procedure OnWebKitInitialized; override; end; TTestExtension = class class function hello: string; class procedure mouseover(const data: string); end; procedure TCustomRenderProcessHandler.OnWebKitInitialized; begin {$IFDEF DELPHI14_UP} TCefRTTIExtension.Register('app', TTestExtension); {$ENDIF} end; class procedure TTestExtension.mouseover(const data: string); var msg: ICefProcessMessage; begin msg := TCefProcessMessageRef.New('mouseover'); msg.ArgumentList.SetString(0, data); TCefv8ContextRef.Current.Browser.SendProcessMessage(PID_BROWSER, msg); end; class function TTestExtension.hello: string; begin Result := 'Hello from Delphi'; end; initialization CefRemoteDebuggingPort := 9000; CefRenderProcessHandler := TCustomRenderProcessHandler.Create; CefBrowserProcessHandler := TCefBrowserProcessHandlerOwn.Create;
Delphi執行JS方法
procedure TMainForm.actExecuteJSExecute(Sender: TObject); begin if crm.Browser <> nil then crm.Browser.MainFrame.ExecuteJavaScript( 'alert(''JavaScript execute works!'');', 'about:blank', 0); end;
一般單進程模式是用來調試的,release版本最好是多進程模式,如果debug版本也是多進程的話,由於Browser、Rendder等進程是獨立分開的,所以即便在一些函數中打上斷點也進不去!而單進程話就都可以進去。至於debug版本多進程模式下為何會彈出兩個主程序窗口我也不是很清楚,但是release版本多進程模式下就正常了,只有一個主程序窗口。並且多進程模式下調用CefShutdown就是OK的,app也能夠正常析構,而單進程模式調用CefShutdown會直接崩潰!
另外,官方文檔上說release版本單進程不是很穩定,不建議使用單進程模式