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

  1. Create project using any template
  2. 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

Most upvoted comments

Oops… actually the CreateCoreWebView2Controller function runs successfully. Just realized that

_, _, err = env.vtbl.CreateCoreWebView2Controller.Call(
	uintptr(unsafe.Pointer(env)),
	e.hwnd,
	uintptr(unsafe.Pointer(e.controllerCompleted)),
)

is not a right way to handle an error as it returns HRESULT value to indicate an error.

public HRESULT CreateCoreWebView2Controller(HWND parentWindow, ICoreWebView2CreateCoreWebView2ControllerCompletedHandler * handler)

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

hres, _, _ := env.vtbl.CreateCoreWebView2Controller.Call(
	uintptr(unsafe.Pointer(env)),
	e.hwnd,
	uintptr(unsafe.Pointer(e.controllerCompleted)),
)
if int32(hres) < 0 { // HRESULT(int32) smaller then 0 means it failed(https://learn.microsoft.com/en-us/windows/win32/api/winerror/nf-winerror-failed)
	// https://learn.microsoft.com/en-us/windows/win32/seccrypto/common-hresult-values
	// do error handling with the HRESULT value 
}

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

,000000B71A3FEA78,00007FFCA356383C,00007FFCA34DA496,30,System,user32.ValidateDpiAwarenessContext+22
,000000B71A3FEAA8,00007FFC80100B0F,00007FFCA356383C,80,User,user32.AreDpiAwarenessContextsEqual+1C
,000000B71A3FEB28,00007FFC80124C66,00007FFC80100B0F,2E0,User,"embeddedbrowserwebview.public: long __cdecl embedded_browser_webview_current::Controller::Initialize(struct HWND__*, struct IUnknown *, class embedded_browser::mojom::EmbeddedBrowser *)+27D"
,000000B71A3FEE08,00007FFC80117134,00007FFC80124C66,1D0,User,"embeddedbrowserwebview.public: long __cdecl embedded_browser_webview_current::EmbeddedBrowserWebView::RuntimeClassInitialize(class std::__Cr::unique_ptr<struct embedded_browser_webview_current::WebViewCreationParams, struct std::__Cr::default_delete<struct embedded_browser_webv"
,000000B71A3FEFD8,00007FFC8011A396,00007FFC80117134,F0,User,embeddedbrowserwebview.embedded_browser_webview_current::internal::EBWebViewEnvironment::CreateWebViewGeneric+5AC
,000000B71A3FF0C8,0000000000B00189,00007FFC8011A396,170,User,"embeddedbrowserwebview.public: virtual long __cdecl embedded_browser_webview_current::internal::EBWebViewEnvironment::CreateCoreWebView2ControllerWithOptions(struct HWND__*, struct ICoreWebView2ControllerOptions *, struct ICoreWebView2CreateCoreWebView2ControllerCompletedHandle"
,000000B71A3FF238,0000000000AFE50D,0000000000B00189,30,User,go-gui.0000000000B00189
,000000B71A3FF268,0000000000AFE583,0000000000AFE50D,8E5DA8408,User,go-gui.0000000000AFE50D
,000000C0001A7670,0000000000AF0332,0000000000AFE583,68,User,go-gui.0000000000AFE583
,000000C0001A76D8,0000000000ADF1C9,0000000000AF0332,28,User,go-gui.0000000000AF0332
,000000C0001A7700,0000000000AFA609,0000000000ADF1C9,50,User,go-gui.0000000000ADF1C9
,000000C0001A7750,0000000001047815,0000000000AFA609,6B8,User,go-gui.0000000000AFA609
,000000C0001A7E08,0000000001042C76,0000000001047815,1E8,User,go-gui.0000000001047815
,000000C0001A7FF0,000000000104BD54,0000000001042C76,40,User,go-gui.0000000001042C76
,000000C0001A8030,0000000000FA60E2,000000000104BD54,68,User,go-gui.000000000104BD54
,000000C0001A8098,0000000000FA62F7,0000000000FA60E2,48,User,go-gui.0000000000FA60E2
,000000C0001A80E0,0000000000AFCEC8,0000000000FA62F7,30,User,go-gui.0000000000FA62F7
,000000C0001A8110,0000000000ADF0A6,0000000000AFCEC8,3F0,User,go-gui.0000000000AFCEC8
,000000C0001A8500,0000000000A8A274,0000000000ADF0A6,B8,User,go-gui.0000000000ADF0A6
,000000C0001A85B8,0000000000A89F87,0000000000A8A274,80,User,go-gui.0000000000A8A274
,000000C0001A8638,0000000000B046EE,0000000000A89F87,28,User,go-gui.0000000000A89F87
,000000C0001A8660,0000000000AFE6CC,0000000000B046EE,FFFFFFF71A256C40,User,go-gui.0000000000B046EE
,000000B71A3FF2A0,0000000000B00495,0000000000AFE6CC,8,User,go-gui.0000000000AFE6CC
,000000B71A3FF2A8,0000000000ADEE3F,0000000000B00495,8,User,go-gui.0000000000B00495
,000000B71A3FF2B0,000000B71A3FF2C0,0000000000ADEE3F,8,User,go-gui.0000000000ADEE3F
,000000B71A3FF2B8,0000000000000000,000000B71A3FF2C0,,User,000000B71A3FF2C0

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_PARAMETER and 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 returns ERROR_PROC_NOT_FOUND in 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.