如何在Tauri中调用WebView2固定版本?Tauri是否支持使用WebView2固定版本?
Hey there! Let's tackle this Tauri + WebView2 embedded runtime issue you're facing for your enterprise app. I've dealt with similar scenarios before, so here's a step-by-step solution that should get you up and running without requiring clients to install WebView2:
First, Understand the Core Issue
Your earlier attempt to use an extracted WebView2 CAB folder didn't work because Tauri defaults to looking for the system-wide WebView2 runtime. We need to explicitly configure Tauri to use an embedded, local copy of the runtime instead.
Step 1: Grab the Fixed Version WebView2 Runtime
Since your app only serves static, bundled HTML and you don't want automatic updates, go with the Fixed Version of WebView2 (not the Evergreen one). Download the CAB package matching your app's architecture (x64/x86/arm64), then extract all its contents into a folder in your Tauri project—something like src-tauri/webview2 works well.
Step 2: Update Your tauri.conf.json
You need two key configuration tweaks to tell Tauri about the embedded runtime:
- In the
tauri > windowssection, add thewebview2InstallModesetting to point to your extracted WebView2 folder:"windows": [ { "title": "Your Enterprise App", "width": 1024, "height": 768, "webview2InstallMode": { "type": "embedded", "path": "./webview2" } } ] - In the
tauri > bundle > windowssection, make sure the WebView2 folder gets included in your MSI package:"bundle": { "windows": { "wix": { // Keep your existing WIX configuration here }, "include": [ "./webview2/**/*" ] } }
Step 3: Rebuild and Test
Run cargo tauri build to package your app with the embedded WebView2 runtime. Then test the resulting MSI on a clean Windows machine (with no WebView2 installed) to confirm it launches correctly—this mimics your clients' environment.
Quick Notes for Enterprise Use
- Stick with Fixed Version WebView2 to avoid unwanted auto-updates that could disrupt your app's behavior.
- Double-check the extracted
webview2folder has all core files (likemsedgewebview2.exe)—don't skip any files from the CAB. - If you're using WIX for deployment, the
includesetting ensures all WebView2 files get copied to the app's installation directory alongside yourapp.exe, just like your old CefSharp setup.
内容的提问来源于stack exchange,提问作者JimSTAT




