Open stephenteodori opened 2 years ago
It was also briefly tested using Microsoft Server 2008 R2, but we don't have ready access to that machine
Hey @stephenteodori - thanks for the bug report!
I haven't seen that error code from that function before. If you wanted to try a few things:
@champnic I tried a test build where it ignored the error. It then calls CoreWebView2Environment.CreateAsync
and WebView2.EnsureCoreWebView2Async
. Both worked successfully and the page loaded. I didn't do an extensive test of functionality though. Also I still logged the error, so GetAvailableBrowserVersionString
is still throwing the same exception when those other commands work as expected.
In terms of trying a different folder, I tried installing in C:\Program Files (x86)
instead of the user account folder with the same results.
Thanks for verifying! I've added this bug to our backlog.
In the cases where it loaded fine, does CoreWebView2Environment.BrowserVersionString
after initialization correctly give a value?
@champnic WebView2.CoreWebView2.Environment.BrowserVersionString
correctly reports the version after initialization.
@champnic - Just checking if there has been any movement on this bug. Thanks!
No updates yet. It doesn't look like we've investigated this bug yet, sorry.
Same thing is happening to me in 1 laptop out of 10 identical laptops (Windows 7 SP1 32-bit) WebView2 v102.0.1245.41 (fixed deployment), WinForms The error is:
System.Runtime.InteropServices.COMException (0x80070032): The request is not supported. (Exception from HRESULT: 0x80070032)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at Microsoft.Web.WebView2.Core.CoreWebView2Environment.GetAvailableBrowserVersionString(String browserExecutableFolder)
at EdgeBrowser.Form1.<InitializeAsync>d__2.MoveNext()
If I skip the call to GetAvailableBrowserVersionString
, browser loads successfully.
The code I use is:
public partial class Form1 : Form
{
WebView2 browser;
public Form1()
{
InitializeComponent();
InitializeAsync();
}
public async Task InitializeAsync()
{
string browserPath = @"..\WebView2Runtime";
try
{
var browserVersionString = CoreWebView2Environment.GetAvailableBrowserVersionString(browserPath);
this.Text += " " + browserVersionString;
var browserUserDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "WebView2");
var webView2Environment = await CoreWebView2Environment.CreateAsync(browserPath, browserUserDataFolder);
browser = new WebView2();
browser.Dock = DockStyle.Fill;
browser.Parent = this;
await browser.EnsureCoreWebView2Async(webView2Environment);
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
}
@Wizard13 If you are using a fixed version deployment, then there may not be a lot of value to calling GetAvailableBrowserVersionString anyways, as your app is typically the one controlling the version and deployment of the runtime.
@champnic , Yes I know, I just wanted to share my code if it helps.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using Microsoft.Web.WebView2.Core;
using Microsoft.Web.WebView2.Wpf;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace HelloWorldWPF
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Loaded += MainWindow_Loaded;
}
private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
Debug.WriteLine($"Navigation to");
try
{
// 创建一个用户数据文件夹在一个有写权限的位置
string userDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "WebView2TestApp");
CoreWebView2EnvironmentOptions options = new CoreWebView2EnvironmentOptions(userDataFolder);
string canaryPath = @"C:\Users\cuiji\AppData\Local\Microsoft\Edge SxS\Application\118.0.2069.0";
CoreWebView2Environment environment = await CoreWebView2Environment.CreateAsync(canaryPath, userDataFolder, options);
await MyWebView.EnsureCoreWebView2Async(environment);
MyWebView.Source = new Uri("https://www.baidu.com");
MyWebView.NavigationCompleted += MyWebView_NavigationCompleted;
}
catch (Exception ex)
{
MessageBox.Show($"An error occurred: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private async void test()
{
CoreWebView2 m_coreWebView2 = MyWebView.CoreWebView2;
// 获取已安装扩展的列表
IReadOnlyList<CoreWebView2BrowserExtension> extensionsList = await m_coreWebView2.Profile.GetBrowserExtensionsAsync();
// 打印或处理扩展列表
foreach (var extension in extensionsList)
{
Debug.WriteLine($"Extension Name: {extension.Name}, ID: {extension.Id}, Enabled: {extension.IsEnabled}");
}
await m_coreWebView2.Profile.AddBrowserExtensionAsync("D:\\work\\zhubajie\\浏览器\\bro\\bro\\chajian\\测试插件");
}
private void MyWebView_NavigationCompleted(object sender, CoreWebView2NavigationCompletedEventArgs e)
{
if (e.IsSuccess)
{
test();
string version = MyWebView.CoreWebView2.Environment.BrowserVersionString;
System.Diagnostics.Debug.WriteLine($"WebView2 version: {version}");
Debug.WriteLine($"Navigation to {MyWebView.Source} completed successfully.");
}
else
{
Debug.WriteLine($"Navigation to {MyWebView.Source} failed: {e.WebErrorStatus}");
}
}
}
}
//This code also has this error // await m_coreWebView2.Profile.AddBrowserExtensionAsync("D:\work\zhubajie\浏览器\bro\bro\chajian\测试插件");
@cuijixiong1 This looks like it might be a separate issue, with a failure in the new Extension APIs? Want to open a new GH issue/bug if so?
@champnic, I'm also experiencing this issue on server 2012 R2 with runtime version 109.0.1518.140.
get the exact error message when trying to call GetAvailableBrowserVersionString()
Description During application startup we call
GetAvailableBrowserVersionString
using a relative path (e.g.path/to/runtime
) to a folder containing the fixed runtime. On Windows Server 2012 R2 the call throws the error that I've included below. The error does not occur on Windows 10 or Windows 7. The error also never occurred with the previous runtime (runtime 94.0.992.31, sdk 1.0.902.49). I have not yet tested whether it will still run since our application exits if it doesn't think a valid runtime is available.Version SDK: 1.0.1054.31 Runtime: 96.0.1054.43 x86 (from Microsoft.WebView2.FixedVersionRuntime.96.0.1054.43.x86.cab) Framework: WPF (targeting .NET 4.6.1) OS: Microsoft Windows Server 2012 R2 Standard, Version: 6.3.9600 Build 9600. Running on EC2. (.NET 4.8 release 528049)
Repro Steps On Windows 2012 R2, call
GetAvailableBrowserVersionString
pointed at a folder containing fixed runtime 96.0.1054.43 x86. Should return the available runtime, instead throws exception.Additional context Application is installed as a user install running from
%localappdata%\Programs\CompanyName\AppName
, running as administrator did not change results.AB#37425847