wails: Error detected in Webview2: The parameter is incorrect
Description
I get this error when I try to run the application on Windows 10 Version 1607 (OS Build 14393.2906)
Error detected in Webview2: The parameter is incorrect. [0920/021755.722:ERROR:window_impl.cc(121)] Failed to unregister class Chrome_WidgetWin_0. Error = 1412
This problem occurs when the project uses github.com/wailsapp/go-webview v1.0.16 If I change to github.com/wailsapp/go-webview v1.0.10 the application runs without errors
When I run the same application on my main OS Windows 10 (Build: 22000) there is no such error
To Reproduce
- Create project using any template
- Build the application and run it
Expected behaviour
Running the application should not cause an error on some versions of Windows 10
Screenshots
No response
Attempted Fixes
No response
System Details
# Wails
Version | v2.9.2
# System
| OS | Windows 10 Home
| Version | 2009 (Build: 22000)
| ID | 21H2
| Go Version | go1.22.6
# Dependencies
| Dependency | Package Name | Status | Version
| WebView2 | N/A | Installed | 128.0.2739.79
| Nodejs | N/A | Installed | 20.13.1
| npm | N/A | Installed | 10.8.0
Additional context
No response
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 22 (6 by maintainers)
Commits related to this issue
- Fix focus calls when window is disabled or minimised. Fixes #3759 and #4168 — committed to wailsapp/wails by leaanthony 2 years ago
- Fix focus calls when window is disabled or minimised. Fixes #3759 and #4168 — committed to wailsapp/wails by leaanthony 2 years ago
Oops… actually the
CreateCoreWebView2Controllerfunction runs successfully. Just realized thatis not a right way to handle an error as it returns HRESULT value to indicate an error.
According to syscall.Proc.Call which is used in ComProc.Call when calling the function, the err value is supposed to be a non-nil error(as written in the document). A correct way to handle an error is would be like
Looks like most of the calls using ComProc are handled in an inappropriate way… as it should be implemented following the documentation for each function to work properly.
Creating a wrapper(maybe something like this) to handle HRESULT would be nice.
Digging into the call of CreateCoreWebView2Controller with x64dbg the stack looks like this
The function is called from embeddedbroswerwebview.dll, calling the CreateCoreWebView2ControllerWithOptions function, which internally calls user32.AreDpiAwarenessContextsEqual, this is where the last status is set to
ERROR_INVALID_PARAMETERand continue running the function procedure, but make the function return an error. Additionally, AreDpiAwarenessContextsEqual was introduced in Windows 10 1607, which explains why the function returnsERROR_PROC_NOT_FOUNDin Windows 10 1507.Although it looks like this does not result in the failure of running the WebView2 process, the DPI setting may go weird without properly setting DPI awareness.
Comparing the api call from the WebView2 Sample and the wails application, looks like this functions fails in both of them, but from the WebView2 sample it does not return an error. I would have to investigate further.