edge-developer icon indicating copy to clipboard operation
edge-developer copied to clipboard

Incorrect documentation of `CoreWebView2.AddHostObjectToScript` for WinRT

Open softworkz opened this issue 2 years ago • 4 comments

The documentation for AddHostObjectToScript is incorrect. It's obviously copied from the documentation for the .NET version of WebView2, but for WinRT, the procedures are different (and complicated unfortunately):

https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/winrt/microsoft_web_webview2_core/corewebview2?view=webview2-winrt-1.0.2065-prerelease#addhostobjecttoscript

For WinRT, an insane effort is required which involves creating a separate project for the classes that should be exposed and it also requires adding a C++ project (like WinRtAdapter in the code sample), which creates WinRT/COM definitions, which finally need to be wrapped again via methods from ICoreWebView2DispatchAdapter. (roughly like that)

These procedures are not documented and the current description is wrong for WinRT.


AB#46593196 - Deliverable, auto-created AB#51566922 - Bug, for triage

softworkz avatar Sep 14 '23 23:09 softworkz

Related article: Call native-side WinRT code from web-side code https://learn.microsoft.com/microsoft-edge/webview2/how-to/winrt-from-js

mikehoffms avatar Sep 15 '23 15:09 mikehoffms

Related article: Call native-side WinRT code from web-side code learn.microsoft.com/microsoft-edge/webview2/how-to/winrt-from-js

Yes, I know that article - which is providing correct information.

But the part I referenced above is incorrect.

softworkz avatar Sep 15 '23 17:09 softworkz

Thank you for reporting this. I'm making sure this goes into our backlog.

captainbrosset avatar Sep 18 '23 07:09 captainbrosset

added 2nd AB# at top, for Bug that's being triaged

mikehoffms avatar Jun 04 '24 16:06 mikehoffms