C# WebView2 在你的应用中使用Chromium内核
什么是WebView2?
- Win10上对标Edge浏览器
- Chromium内核
- 简单的可视为WebBrowser组件的升级版
如何使用WebView2?
- 官网下载 WebView2 RunTime
- VS2019 NuGet搜索 WebView2,安装最新版即可
WebView2 具体使用技巧
- 引入
using Microsoft.Web.WebView2.WinForms; - 声明 WebView2,如
var edge=new WebView2(); - 将窗体 Load 事件声明为
async,如private async void ViewForm_Load(object sender, EventArgs e) - 将
edge添加到Controls中,如Controls.Add(edge);edge.Dock = DockStyle.Fill; - 在窗体 Load 事件中 增加
await edge.EnsureCoreWebView2Async();//这步是必须的 - 设置网址,
edge.Source = new Uri("https://www.cnblogs.com");
我想怎么玩?
- WebView2 提供 UI TidyView
- TidyScriptCore 提供 C# 脚本运行
TidyView
- 把 WebView2 封装成 TidyWebView
public class TidyWebView:WebView2
{
public TidyWebView();
public List<Typing.FuncSender> Main;
public Runner ViewRunner;
private void CoreWebView2_DOMContentLoaded(object sender, Microsoft.Web.WebView2.Core.CoreWebView2DOMContentLoadedEventArgs e);
private void TidyWebView_CoreWebView2InitializationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs e);
public string Url{get;set;}
public void Navigate(string Url)
public delegate void CallNone();
public void EvalJS(string Script);
public void EvalTidy(string Script);
private EventCollection EventList;
public int AddFunc(Typing.FuncSender func);
public int AddFunc(string Name,Typing.FuncSender func);
public void CallIndex(int Index,params object[] args);
public void Call(string Name, params object[] args);
}
- 将 TidyWebView 放到窗体
using System;
using System.Windows.Forms;
using System.IO;
using TidyScriptCore;
namespace TidyView
{
public partial class ViewForm : Form
{
public ViewForm()
{
InitializeComponent();
edge.NavigationCompleted += Edge_NavigationCompleted;
Inner.console.host = edge;
}
private void Edge_NavigationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e)
{
Text = edge.CoreWebView2.DocumentTitle;
}
TidyWebView edge = new TidyWebView();
public string CodePath = string.Empty;
private async void ViewForm_Load(object sender, EventArgs e)
{
Tidy.Using(typeof(Inner));
p_web.Controls.Add(edge);
edge.Dock = DockStyle.Fill;
Icon = Properties.Resources.browser;
await edge.EnsureCoreWebView2Async();
edge.ViewRunner.Space.Create("MainForm",this);
if (File.Exists(CodePath))
{
Log.Path = TidyScriptCore.API.GetDir(CodePath) + "\\Logs.txt";
edge.ViewRunner.Environment["ScriptPath"] = CodePath;
edge.ViewRunner.Environment["ScriptDir"] = TidyScriptCore.API.GetDir(CodePath);
Tidy.EvalFile(CodePath,edge.ViewRunner);
}
}
}
}
- 写 TidyScript 脚本 个人门户(密码:Tidy),基本和C#代码风格保持一致
using "Baidu.csc";
using "News.csc";
using "Weather.csc";
edge.AddFunc("search",(kw,filter_str,limit_str,page_str)=>
{
var filter=json.obj(filter_str);
var limit=json.obj(limit_str);
var page=json.obj(page_str);
var filter_lamda;
var bd=new Baidu();
//...
int index=page.start_index;
bd.search(kw,(info)=>
{
//...
if(filter.on){/*...*/}
else
{
edge.EvalJS($"_add({index++},{info});");
}
return true;
},()=>{/*...*/},page.first,page.last);
edge.EvalJS("_show_sufooter()");
});
//...
//...
edge.Main.Add(()=>
{
if(file.exists(locate("filter_code.txt")))
{
var default_code=transfer(file.read(locate("filter_code.txt")));
edge.EvalJS($"document.getElementById('filter_code').value='{default_code}'");
}
});
edge.Url="file:///"+locate("page.html");
右键你写的脚本,用TidyView.exe打开,点击BiliBili

开源项目 TidyView
下一个玩具 FFMPEG Visual ,我打算这么做
- 将功能封装在FfmpegEx.dll中
- TidyView 用来 UI
- 写C#脚本,来桥接 FfmpegEx.dll 和 JS
C# WebView2 在你的应用中使用Chromium内核的更多相关文章
- centos中安装chromium和flash
安装环境:centos 6.5 64位 在centos中安装chromium 安装Google源 cd /etc/yum.repos.d/ sudo wget http://people.CentOS ...
- u-boot中分区和内核MTD分区关系
一.u-boot中环境变量与uImage中MTD的分区关系 分区只是内核的概念,就是说A-B地址放内核,C-D地址放文件系统,(也就是规定哪个地址区间放内核或者文件系统)等等. 一般我们只需要分3-4 ...
- linux中清理旧内核
执行update的时候会自动升级内核,开机启动的时候会好多内核选项.所以我们要清理不需要内核. 查看当前系统使用的内核版本 uname -a Linux localhost.localdomain 3 ...
- .NET混合开发解决方案11 WebView2加载的网页中JS调用C#方法
系列目录 [已更新最新开发文章,点击查看详细] WebView2控件应用详解系列博客 .NET桌面程序集成Web网页开发的十种解决方案 .NET混合开发解决方案1 WebView2简介 .NE ...
- Delphi中Chrome Chromium、Cef3学习笔记(四)
原文 http://blog.csdn.net/xtfnpgy/article/details/48155323 一.遍历网页元素并点击JS: 下面代码为找到淘宝宝贝页面,成交记录元素的代码: ...
- Delphi中Chrome Chromium、Cef3学习笔记(三)
原文 http://blog.csdn.net/xtfnpgy/article/details/46635871 Delphi与JS的交互问题: 一.执行简单的JS 上一篇已经讲过: chrm ...
- Delphi中Chrome Chromium、Cef3学习笔记(二)
原文 http://blog.csdn.net/xtfnpgy/article/details/46635739 用Tchromium替换webbrowser 用惯了EmbeddedWB,不想 ...
- Delphi中Chrome Chromium、Cef3学习笔记(一)
原文 http://blog.csdn.net/xtfnpgy/article/details/46635225 官方下载地址:https://cefbuilds.com/ CEF简介: 嵌入 ...
- Linux2.6.32内核笔记(5)在应用程序中移植使用内核链表【转】
转自:http://blog.csdn.net/Deep_l_zh/article/details/48392935 版权声明:本文为博主原创文章,未经博主允许不得转载. 摘要:将内核链表移植到应用程 ...
随机推荐
- Flutter Navigator2.0
Example 1 import 'package:dart_printf/dart_printf.dart'; import 'package:flutter/material.dart'; cla ...
- PAUL ADAMS ARCHITECT:日本楼市仍保持稳定
日本国土交通省从2008年11月开始,到2020年10月,连续追踪日本的公寓房价和日经指数两个数值的变动关联性,结果显示相关系数是0.935,也就是说在此期间,日本楼市和股市有着非常强的正相关. 保罗 ...
- int和Integer的比较详解
说明: int为基本类型,Integer为包装类型: 装箱: 基本类型---> 包装类型 int ---> Integer 底层源码: .intValue() 拆箱: 包装类型---> ...
- sublime 使用过程中遇到的问题
1.当我把鼠标放置在下图所示的class上几秒钟后,sublime就会在全局查找当前的class字符,这时sublime就会出现卡顿或无响应 解决方法: 点击preferences下的settings ...
- scrapy 运行逻辑
爬虫的步骤:发送请求获得响应→解析并提取数据→保存数据 我们沿用这个朴素的逻辑去理解scrapy 一.发送请求获得响应 1.爬虫发送请求request到引擎 2.引擎将请求request传递给调度器s ...
- 如何使用irealtime.js实现一个基于websocket的同步画板
同步画板演示 同时打开2个tab,分别在画布上写下任意内容,观察演示结果,同时可设置画笔颜色及线条宽度.演示地址 初始化画布 <canvas id="drawBoard" w ...
- 关于使用C3P0程序报错Having failed to acquire a resource, com.mchange.v2.resourcepool的问题
由于是新手的问题,C3P0的使用时严格跟着视频来的,但是问题却来的很突然 在导入了三个包以及创建了路径以后 进行测试 class JdbcutilsTest { @Test void TestGetC ...
- 03.从0实现一个JVM语言系列之语法分析器-Parser-03月01日更新
从0实现JVM语言之语法分析器-Parser 相较于之前有较大更新, 老朋友们可以复盘或者针对bug留言, 我会看到之后答复您! 源码github仓库, 如果这个系列文章对你有帮助, 希望获得你的一个 ...
- 49元起!魅族Lipro LED灯泡发布:无可视频闪、无积热问题
转: 49元起!魅族Lipro LED灯泡发布:无可视频闪.无积热问题 魅族智能家居品牌Lipro今日办会,公布一批新品,均面向健康照明领域打造. 魅族强调,Lipro健康照明产品主打博物馆级健康光. ...
- Hi3559AV100外接UVC/MJPEG相机实时采图设计(一):Linux USB摄像头驱动分析
下面将给出Hi3559AV100外接UVC/MJPEG相机实时采图设计的整体流程,主要实现是通过V4L2接口将UVC/MJPEG相机采集的数据送入至MPP平台,经过VDEC.VPSS.VO最后通过HD ...