本指南帮助你快速开始使用 CEF 和 WebView2 截图工具。
- ✅ Windows 10/11 x64
- ✅ PowerShell 5.1+
- ✅ Visual Studio 2022(含 Desktop C++ workload)
- ✅ Node.js 18+
- ✅ Python 3.x
- ✅ .NET 8 SDK
选择 WebView2 Screenshot Tool,如果:
- ✅ 你需要一个简单的命令行截图工具
- ✅ 你希望最小化依赖和体积
- ✅ 你只在 Windows 平台使用
- ✅ 你不需要深度自定义浏览器行为
选择 CEF Node Addon,如果:
- ✅ 你需要在 Node.js 项目中集成截图功能
- ✅ 你需要完整的 Chromium 功能和自定义选项
- ✅ 你计划未来支持其他平台
- ✅ 你需要更精细的控制(Cookie、证书、GPU 设置等)
winget install Microsoft.DotNet.SDK.8cd packages/webview2-screenshot-tool
dotnet build -c Release# 使用命令行直接运行
.\bin\Release\net8.0\webview2-screenshot.exe `
--url https://example.com `
--output test.png
# 或使用 Node.js demo
node demo.js确保已安装:
- Visual Studio 2022(Desktop C++ workload)
- Node.js 18+
- Python 3.x
安装 CMake:
# 推荐:使用 winget 安装系统级 CMake
winget install Kitware.CMake
# 或者:使用便携版 CMake(下载后添加到 PATH)
# 从 https://cmake.org/download/ 下载
# $env:PATH = "C:\path\to\cmake\bin;$env:PATH"# 回到项目根目录
cd ../..
# 生成并构建 CEF wrapper
cmake `
-S third_party/cef/cef_binary_143.0.6+g05edb3b+chromium-143.0.7499.40_windows64_beta `
-B third_party/cef/build_wrapper `
-G "Visual Studio 17 2022" -A x64
cmake `
--build third_party/cef/build_wrapper `
--config Release `
--target libcef_dll_wrapper
# 复制 lib 文件
Copy-Item third_party/cef/build_wrapper/libcef_dll_wrapper/Release/libcef_dll_wrapper.lib `
third_party/cef/cef_binary_143.0.6+g05edb3b+chromium-143.0.7499.40_windows64_beta/Release/ -Forcecd packages/cef-node-addon
# 设置 CEF_ROOT
$env:CEF_ROOT = (Resolve-Path ../../third_party/cef/cef_binary_143.0.6+g05edb3b+chromium-143.0.7499.40_windows64_beta)
# 安装依赖并构建
npm install --ignore-scripts
npx node-gyp rebuild -- "-DCEF_ROOT=$env:CEF_ROOT"node demo.jswinget install Microsoft.EdgeWebView2Runtime确保安装了 Visual Studio 2022 并包含 "Desktop development with C++" workload。
- 确保 Python 3.x 在 PATH 中
- 确保 Visual Studio 2022 正确安装
- 以管理员身份运行 PowerShell
# 设置环境变量
$env:CEF_ROOT = (Resolve-Path ./third_party/cef/cef_binary_143.0.6+g05edb3b+chromium-143.0.7499.40_windows64_beta)# 安装 CMake
winget install Kitware.CMake
# 或检查 PATH 是否包含 cmake
cmake --version- 阅读 CEF Node Addon 详细文档
- 阅读 WebView2 Screenshot Tool 详细文档
- 查看 主 README 了解项目结构
如遇到问题,请:
- 查看各工具的 README 中的"故障排除"章节
- 在 GitHub Issues 提交问题
- 确保环境符合所有前置要求