是否可以将CefSharp用作"Chrome"?我知道,它是一种Chrome,但网页并没有将CefSharp视为Chrome.故事:我想用CefSharp嵌入WhatsApp Web,但Whatsapp说:只支持Chrome.有没有可能"伪造"Chrome?
我有一个关闭屏幕ChromiumWebBrowser,我用来在页面上运行一些JS并获得结果.
Load方法是同步的,但是在引发FrameLoadEnd事件之前我无法运行JS代码,这意味着或者我的目的Load是一个以FrameLoadEnd事件结束的异步方法.
为了使我的代码更清晰,我尝试创建一个扩展方法,允许我等待页面加载await而不是注册到事件.但是当我在TaskCompletionSource中使用这个方法时,没有加载在页面加载后应该运行的javascript,但是当使用AutoResetEvent并等待它时代码确实有效.
此代码不起作用:
public static Task LoadPageAsync(this IWebBrowser browser, string address)
{
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
browser.FrameLoadEnd += (sender, args) =>
{
if (args.IsMainFrame)
{
tcs.TrySetResult(true);
}
};
browser.Load(address);
return tcs.Task;
}
Run Code Online (Sandbox Code Playgroud)
这样做:
public static AutoResetEvent LoadPageAsync(this IWebBrowser browser, string address)
{
AutoResetEvent are = new AutoResetEvent(false);
browser.FrameLoadEnd += (sender, args) =>
{
if (args.IsMainFrame)
{
are.Set();
}
};
browser.Load(address);
return are;
}
Run Code Online (Sandbox Code Playgroud)
这是调用代码:
await _browser.LoadPageAsync("Some web address");
LoadScripts();
DoJsThing();
GetJsData();
Run Code Online (Sandbox Code Playgroud)
他们做同样的事情,但我觉得返回任务时函数的意图要比返回AutoResetEvent时更清楚. …
在CefSharp WinForms中,我试图在页面加载后使用JS获取页面的html源代码,但是应用程序正在冻结.我正在使用BackgroundWorker,相关功能如下:
void bw_DoWork(object sender, DoWorkEventArgs e)
{
browser.Load("http://www.google.com");
browser.FrameLoadEnd += delegate
{
object js = EvaluateScript(browser, "1+1");
MessageBox.Show(js.ToString());
};
}
object EvaluateScript(ChromiumWebBrowser b, string script)
{
var task = b.EvaluateScriptAsync(script);
task.Wait();
return task.Result;
}
Run Code Online (Sandbox Code Playgroud) 我正在使用cefSharp. 现在我需要像Google Chromehas一样向用户提供文本搜索功能。任何人都可以帮助我在cefSharp.
如何使用CefSharp获取HTML元素的值?
我知道如何处理这个默认的WebBrowser控件:
Dim Elem As HtmlElement = WebBrowser1.Document.GetElementByID("id")
Run Code Online (Sandbox Code Playgroud)
但我没有找到类似的CefSharp.我使用CefSharp的主要原因是因为网站的一部分使用iframe来存储源,而默认的WebBrowser不支持它.此外,CefSharp是否可以选择InvokeMember或类似的呼叫?
顺便说一下,我正在使用最新版本的CefSharp.
如何从 CefSharp 中的 JS 调用 .NET 异步方法。我想调用一个等待控制台应用程序调用的方法。
我的想法如下:我用下面的签名调用一个方法:
public async Task<int> Calculate(){
Run Code Online (Sandbox Code Playgroud)
当它完成时,它的结果由 JS 端的承诺返回。目前,它不起作用。完成后没有回调,然后我无法再次调用它。
谢谢
我有一个部署在客户端计算机上的C#控制台应用程序.在客户端计算机中部署时,我得到System.TypeInitializationException.
在debug.log中,我收到以下错误:
Unable to locate required Cef/CefSharp dependencies:
Missing:CefSharp.BrowserSubprocess.exe
Missing:CefSharp.BrowserSubprocess.Core.dll
Missing:CefSharp.Core.dll
Missing:CefSharp.dll
Missing:icudtl.dat
Missing:libcef.dll
Executing Assembly Path:C:\myapp
Run Code Online (Sandbox Code Playgroud)
问题是所有文件都存在于C:\ myapp目录中(如此处所指定).因此,我不确定为什么这些文件没有被加载.msvcp120.dll,msvcr120.dll,vccorlib120.dll也包含在c:\ myapp目录中
我正在尝试在C#winforms中使用cefshar浏览器,并且需要知道如何完全加载页面以及如何获取浏览器文档和html元素,
我只是初始化浏览器,不知道下一步该怎么做:
public Form1()
{
InitializeComponent();
Cef.Initialize(new CefSettings());
browser = new ChromiumWebBrowser("http://google.com");
BrowserContainer.Controls.Add(browser);
browser.Dock = DockStyle.Fill;
}
Run Code Online (Sandbox Code Playgroud) 我对CefSharp浏览器不太满意,因此我需要一些外部帮助。
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;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace WindowsFormsApplication7
{
public partial class debug : Form
{
public ChromiumWebBrowser browser;
public debug()
{
InitializeComponent();
InitBrowser();
}
private void debug_Load(object sender, EventArgs e)
{
}
public void InitBrowser()
{
Cef.Initialize(new CefSettings());
browser = new ChromiumWebBrowser("https://whatismyipaddress.com/");
this.Controls.Add(browser);
browser.Dock = DockStyle.Fill;
CefSettings cfsettings = new CefSettings();
cfsettings.CefCommandLineArgs.Add("proxy-server", "200.29.191.149:3128");
cfsettings.UserAgent = "My/Custom/User-Agent-AndStuff";
Cef.Initialize(cfsettings);
} …Run Code Online (Sandbox Code Playgroud) 我在C#WPF应用程序中使用CefSharp 57.
我想在任何给定的网页上隐藏垂直和水平滚动条.
我一直无法找到直接用CefSharp做到这一点的方法.
它似乎没有类似于ScrollBarsEnabled我习惯使用本机WinForms浏览器的属性.
我想我可能会在页面渲染后注入一些CSS/JS来将body溢出设置为隐藏但这没有任何效果.
private void OnBrowserFrameLoadEnd(object sender, FrameLoadEndEventArgs args)
{
if (args.Frame.IsMain)
{
// Shows an alert after page is loaded so it definitely works
args
.Browser
.MainFrame
.ExecuteJavaScriptAsync("alert('HELLO!');
// Scrollbars are still visible after this fires
args
.Browser
.MainFrame
.ExecuteJavaScriptAsync(
"(function() { document.body.style.overflow = 'hidden'; });");
}
}
Run Code Online (Sandbox Code Playgroud)
我看看是否有办法自己绘制滚动条并使它们透明,但我无法找到方法来做到这一点.
有没有办法使用CefSharp隐藏任何给定页面上的垂直和水平滚动条?
cefsharp ×10
c# ×9
.net ×1
64-bit ×1
async-await ×1
asynchronous ×1
c#-4.0 ×1
javascript ×1
proxy ×1
text-search ×1
vb.net ×1
whatsapp ×1
wpf ×1