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 版权声明:本文为博主原创文章,未经博主允许不得转载. 摘要:将内核链表移植到应用程 ...
随机推荐
- NGK公链账本技术浅析
NGK公链账本是一个去中心化加密账本,运行在分布式网络上.分布式账本是区块链技术中最重要的组成部分之一.NGK作为公链资产,在公链中起到桥梁作用,可以促进其他资产(法币.数字资产.股权以及实物资产)交 ...
- WLAN-AC+AP射频一劳永逸的调优方式
AP射频调优组网图 射频调优简介 射频调优的主要功能就是动态调整AP的信道和功率,可以使同一AC管理的各AP的信道和功率保持相对平衡,保证AP工作在最佳状态.WLAN网络中,AP的工作状态会受到周围环 ...
- Echart饼图旋转
1 <!DOCTYPE html> 2 <html lang="en"> 3 4 <head> 5 <meta charset=" ...
- Django模型层2
目录 一.聚合查询 聚合函数 二.分组查询 利用group by进行分组查询 三.F与Q查询 1. F类 2. Q类 四.orm字段及参数 五.自定义char字段 六.orm中的事务操作 1. 什么是 ...
- go的循环
目录 go的循环 一.语法 二.语法简写 1.省略第一部分 2.省略第二部分 3.省略第三部分 4.全省略:死循环 5.终极写法,简洁变形 go的循环 Go中只有for循环,没有while循环.因为w ...
- mysql日志系统简单使用
MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,属于 Oracle 旗下产品.MySQL 是最流行的关系型数据库管理系统之一,在 WEB 应用方面,MySQL是最好的 RDBM ...
- 基于docker创建Cassandra集群
一.概述 简介 Cassandra是一个开源分布式NoSQL数据库系统. 它最初由Facebook开发,用于储存收件箱等简单格式数据,集GoogleBigTable的数据模型与Amazon Dynam ...
- Qstring和String的区别
QString qTest; std::string sTest = qTest.toStdString(); qTest = QString::fromStdString(sTest); //进入两 ...
- Centos7安装Docker&镜像加速
目录 Docker Docker安装 方式一 方式二 docker 镜像加速 Docker Docker安装 Docker安装 方式一 step1: 删除老版本(Uninstall old versi ...
- Flask:处理Web表单
尽管 Flask 的请求对象提供的信息足以处理 Web 表单,但有些任务很单调,而且要重复操作.比如,生成表单的 HTML 代码和验证提交的表单数据.Flask-WTF 扩展可以把处理 Web 表单的 ...