MicrosoftEdge / MicrosoftEdge/WebView2Feedback

Accessing a function with parameter that is added using AddHostObjectToScript returns "Parameter is incorrect."

Open
#1,789 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug tracked
Dominant language
PowerShell
Stars
526
Forks
67
PR merge metrics
No merged PRs in 30d

Description

Description
Hello, I'm new to WebView2 and I've been trying to understand how the code-sharing aspect of it works. Recently, I have been trying out the Host object approach and it only works for me when the function has no required parameter.

Version
SDK:
Runtime:
Framework: WinUI
OS: Win10

Repro Steps

I have tried passing a parameter in my Angular app it like this:
var result = window?.chrome?.webview?.hostObjects.sync.myObject.SayHello("John");

and I keep on getting this error:
image

I have also tried using the following code:
window?.chrome?.webview?.hostObjects.sync.myObject().SayHello("John");

and it gives a different error:
image

This is what my code behind looks like:
image
image
**NOTE: I am using an interface as webView.CoreWebView2.AddHostObjectToScript() throws an NotImplementedError

Screenshots

Additional context

AB#34516976

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the WinUI host-object setup and the Angular calls to window.chrome.webview.hostObjects.sync.myObject.SayHello("John") and the alternate invocation shown in the issue. Reproduce both errors using the reported WebView2 configuration, then establish whether parameterized SayHello calls are expected to work and document the confirmed behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, javascript
Domain
api, desktop
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.