制作浏览器CEFSharp133+X86+win7 之配置环境(一)
============================================
一定要设置项目为x86或者x64
=============================================
1、FrameWork
引用下面四个dll,并且不要输出到目录,属性==》复制到本地=》false
CefSharp.dll
CefSharp.Core.dll
CefSharp.Core.Runtime.dll
CefSharp.WinForms.dll
App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="cef" />
</assemblyBinding>
</runtime>
</configuration>
====================================================
2、NetCore
引用下面三个dll,并且不要输出到目录,复制到本地==》否
CefSharp.dll
CefSharp.Core.dll
CefSharp.WinForms.dll
Program.cs
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
//LoadFrom会自动加载依赖(如果程序集位于GAC中,则LoadFrom将自动加载GAC中的程序集)
Assembly.LoadFrom($@"{AppDomain.CurrentDomain.BaseDirectory}cef\CefSharp.dll");
Assembly.LoadFrom($@"{AppDomain.CurrentDomain.BaseDirectory}cef\CefSharp.Core.dll");
Assembly.LoadFrom($@"{AppDomain.CurrentDomain.BaseDirectory}cef\CefSharp.Core.Runtime.dll");
Assembly.LoadFrom($@"{AppDomain.CurrentDomain.BaseDirectory}cef\CefSharp.WinForms.dll");
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
}
}
=======================================================
using CefSharp.WinForms;
using CefSharp;namespace TestCefCore
{public partial class Form1 : Form{public Form1(){InitializeComponent();var settings = new CefSettings(){Locale = "zh-CN",AcceptLanguageList = "zh-CN,zh;q=0.8",PersistSessionCookies = true,UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0 Safari/537.36",IgnoreCertificateErrors = true,LogSeverity = LogSeverity.Disable, //禁用日志//为空则将以“隐身模式”创建浏览器CachePath = AppDomain.CurrentDomain.BaseDirectory + "cef_cache",//Windows上用户“Local Settings\Application Data\CEF\User Data”目录RootCachePath = AppDomain.CurrentDomain.BaseDirectory + "cef_temp"};settings.CefCommandLineArgs.Add("disable-gpu", "1"); // 禁用gpusettings.CefCommandLineArgs.Add("no-proxy-server", "1"); //禁用代理settings.CefCommandLineArgs.Add("proxy-auto-detect", "0"); //禁用代理//settings.CefCommandLineArgs.Add("proxy-server", "ProxyAddress");settings.CefCommandLineArgs.Add("--disable-web-security", "1"); //允许跨域settings.CefCommandLineArgs.Add("--ignore-urlfetcher-cert-requests", "1");//忽略安全证书settings.CefCommandLineArgs.Add("--ignore-certificate-errors", "1");//忽略安全证书settings.CefCommandLineArgs.Add("enable-media-stream", "1"); //允许webRTC//settings.CefCommandLineArgs["enable-system-flash"] = "1";//settings.CefCommandLineArgs.Add("ppapi-flash-version", "32.0.0.171");//settings.CefCommandLineArgs.Add("ppapi-flash-path", @"plugins\pepflashplayer.dll");//Cef.EnableHighDPISupport();CefSharpSettings.ConcurrentTaskExecution = true;//CefSharpSettings.LegacyJavascriptBindingEnabled = true;//CefSharpSettings.WcfEnabled = true;Cef.Initialize(settings);}
窗口代码
ChromiumWebBrowser webview;private void Form1_Shown(object sender, EventArgs e){var url = "https://www.tesla.cn/ownersmanual/modelx/en_qa/Owners_Manual.pdf";//url = "https://lib.tsinghua.edu.cn/wj/GBT7714-2015.pdf";//url = "https://www.baidu.com";url = "http://127.0.0.1:5500/index.html";webview = new ChromiumWebBrowser(url);webview.BrowserSettings.WebGl = CefState.Enabled;webview.Dock = DockStyle.Fill;Controls.Add(webview);}private void Form1_FormClosing(object sender, FormClosingEventArgs e){Cef.Shutdown();}}
}
阿雪技术观
在科技发展浪潮中,我们不妨积极投身技术共享。不满足于做受益者,更要主动担当贡献者。无论是分享代码、撰写技术博客,还是参与开源项目维护改进,每一个微小举动都可能蕴含推动技术进步的巨大能量。东方仙盟是汇聚力量的天地,我们携手在此探索硅基生命,为科技进步添砖加瓦。
Hey folks, in this wild tech - driven world, why not dive headfirst into the whole tech - sharing scene? Don't just be the one reaping all the benefits; step up and be a contributor too. Whether you're tossing out your code snippets, hammering out some tech blogs, or getting your hands dirty with maintaining and sprucing up open - source projects, every little thing you do might just end up being a massive force that pushes tech forward. And guess what? The Eastern FairyAlliance is this awesome place where we all come together. We're gonna team up and explore the whole silicon - based life thing, and in the process, we'll be fueling the growth of technology.