Skip to content

[Problem/Bug]: Can't use methods on COM Object passed with AddHostObjectToScript #5272

Open
@Rokuo

Description

@Rokuo

What happened?

Hi,

In a native application i'm upgrading my frontend with webviews in order to upgrade my JS in ES3 to newer version.
I created a component to hold the webview and in order to have all my functionnalities back with the webview I do need to send an object to the script, I saw that we could achieve that by adding the object to the hostObjects of the webview component. (AddHostObjectToScript method)

I can pass my object to my javascript in the webview just fine but i just can't use any methods that needs parameters it's firing an error saying "Non optional parameter" (idk why it's in french in the screen)

Image

Upon inspecting the call in the Invoke method of the COleDispatchImpl class, the pDispParams->cArgs value is 0, which confirms that the parameters aren't being transmitted properly.

Image

I've seen posts discussing similar issues dating back several years, but I haven't found a clear solution.
Is this a known limitation of the WebView host object model, or is there an alternative way to pass arguments to host object methods?

Unfortunately, I’m not entirely sure which framework is being used for the WebView (likely WebView2 or an earlier variant), but I’m hoping that’s not critical for resolving the core issue.

Any guidance would be appreciated.

Thanks!

Importance

Blocking. My app's basic functions are not working due to this issue.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

137.0.3296.68

SDK Version

1.0.3296.44

Framework

Win32

Operating System

Windows 11

OS Version

22631.5472

Repro steps

In order to reproduce this issue i've attached a zip of a sample project where i'm trying to send a CCalculator class into hostObject with minimal methods or properties. It is from a sample if my memory serves me right that has already been shared in another github from MicrosoftEdge.

Win32_GettingStarted.zip

In order to reproduce the step you need to :

  1. Build the solution
  2. Start the project WebView2GettingStarted
  3. It should show you a Microsoft Bing page :

Image

  1. Go into the dev console where you can type some javascript and you'll be able to test if the hostObject is properly usable or not.

Image

You should be able to reproduce the error as shown
Also to be noted is that methods without params seems to be working but need to be called as properties (Calculator.NoArgs that is a method and not a property)

Repros in Edge Browser

Yes, issue can be reproduced in the corresponding Edge version

Regression

No, this never worked

Last working version (if regression)

No response

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions