/** * JS 스크립트 실행 * @param jsString * @param document */ public void ExecuteJS(String jsString, CefSharp.IFrame document) { this.webBrowser.Invoke(new Action(() => { String command = String.Format(@" (function() {{ window.requestAnimationFrame(function() {{ {0} }}); }}) ", jsString); String script = String.Format(@"(function() {{ if (document.readyState != 'loading') {{ {0}(); }} else if (document.addEventListener) {{ document.addEventListener('DOMContentLoaded', {0}); }} else {{ document.attachEvent('onreadystatechange', function() {{ if (document.readyState != 'loading') {0}(); }}); }} }})()", command); //JavascriptResponse resutls = await document.EvaluateScriptAsync(script); document.ExecuteJavaScriptAsync(script); })); }
public static cefS.JavascriptResponse uJsExec(uChrome agrBrowser, string argJs) { List <long> frameIdList = agrBrowser.uBrowser.GetBrowser().GetFrameIdentifiers(); cefS.IFrame frame = agrBrowser.uBrowser.GetBrowser().GetFrame(frameIdList.First()); var t = frame.EvaluateScriptAsync(argJs); t.Wait(); return(t.Result); }
//解析Task public async Task <int> ExcuteAnalysis(CustomChrominWebBrowser w, CefSharp.IFrame frame, LinkedList <Models.Task> Rules, Models.Task infoTask, TaskViewModel taskViewModel) { int index = 0; int ErrorCount = 0; foreach (var item in Rules) { object symbol = true; if (item.MatchSymbol != null) { symbol = Convert.ToBoolean(await TaskHelper.Excute(frame, (string)item.MatchSymbol)); } //获取页面缓存数据集 Dictionary <string, NetSource> FileData = ((CustomRequestHandler)w.RequestHandler).GetMemoryData(); if ((bool)symbol) { index++; LogHelper.Debug(string.Format("规则[{0}]匹配标记 返回True,将执行此规则", item.Action)); //转换任务Task到解析Task item.ConvertToRunTask(infoTask); try { var _result = await TaskHelper.Excute(w, FileData, frame, item, taskViewModel); if (_result) { LogHelper.Debug(string.Format("{0}完成解析任务{1}", w.ID, item.ID)); } else { LogHelper.Debug(string.Format("{0}在解析任务{1}时出现错误", w.ID, item.ID)); } } catch (Exception e) { ErrorCount++; LogHelper.Debug(string.Format("{0}在解析任务{1}时出现错误 Error:{2}", w.ID, item.ID, e.Message)); } } else { LogHelper.Debug(string.Format("规则[{0}]匹配标记 返回False,将跳过此规则", item.Action)); } } //清除页面文件的自定义缓存数据 ((CustomRequestHandler)w.RequestHandler).ReleaseCustomData(); if (Rules.Count == 0) { LogHelper.Debug(string.Format("{0} 没有匹配的规则用于解析[{1}]", w.ID, w.Info?.Action)); } return(ErrorCount); }
private void btnShot_Click(object sender, RoutedEventArgs e) { int areaHeight = 0, areaWidth = 0; Position areaPos = null; Position dialogPos; JavaScriptSerializer json = new JavaScriptSerializer(); Invoice inv = listView.SelectedItem as Invoice; string cmd = string.Format("JSON.stringify($(\"#dialog-body\").offset())"); string dialogOffset = (string)browser.GetBrowser().MainFrame.EvaluateScriptAsync(cmd).Result.Result; if (dialogOffset == null) { return; } dialogPos = json.Deserialize <Position>(dialogOffset); browser.GetBrowser().GetFrameIdentifiers().ForEach(t => { CefSharp.IFrame frame = browser.GetBrowser().GetFrame(t); if (frame.IsMain) { return; } else { cmd = string.Format("JSON.stringify($(\"#print_area\").offset())"); string areaOffset = (string)frame.EvaluateScriptAsync(cmd).Result.Result; areaPos = json.Deserialize <Position>(areaOffset); cmd = string.Format("$(\"#print_area\").outerHeight()"); areaHeight = (int)frame.EvaluateScriptAsync(cmd).Result.Result; cmd = string.Format("$(\"#print_area\").outerWidth()"); areaWidth = (int)frame.EvaluateScriptAsync(cmd).Result.Result; } }); if (areaPos != null) { areaPos += dialogPos; Int32Rect rect = new Int32Rect((int)areaPos.Left, (int)areaPos.Top, areaWidth, areaHeight); System.Windows.Controls.Image contentImage = browser.Content as System.Windows.Controls.Image; BitmapSource bs = contentImage.Source.Clone() as BitmapSource; CroppedBitmap img = new CroppedBitmap(bs, rect); inv.Result = img; } }
bool CefSharp.IContextMenuHandler.RunContextMenu(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IContextMenuParams parameters, CefSharp.IMenuModel model, CefSharp.IRunContextMenuCallback callback) { return(false); }
void CefSharp.IContextMenuHandler.OnContextMenuDismissed(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame) { //throw new NotImplementedException(); }
bool CefSharp.IContextMenuHandler.OnContextMenuCommand(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IContextMenuParams parameters, CefSharp.CefMenuCommand commandId, CefSharp.CefEventFlags eventFlags) { //throw new NotImplementedException(); return(false); }
void CefSharp.IContextMenuHandler.OnBeforeContextMenu(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IContextMenuParams parameters, CefSharp.IMenuModel model) { model.Clear(); }
public HTMLProgressBar(CefSharp.IFrame frame, string id) : base(frame, id) { }
public virtual void SetParent(CefSharp.IFrame parent) { this.parent = parent; }
public HTMLControl(CefSharp.IFrame parent, string id) { this.parent = parent; this.id = id; }