MicrosoftEdge / MicrosoftEdge/WebView2Feedback
Will we ever be able to pass complex objects into and out of our API's ?
Open
@david-risney is already working on this.
Since Jun 22, 2020.
bug
priority-low
tracked
- Dominant language
- PowerShell
- Stars
- 526
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
Hello
Will we ever be able to pass complex objects into and out of our API's ?
I have follow example:
var dataObj= {nameX: 'max monster',messageX: 'lorem ipsum...'};
async function sendData(){
let res = await chrome.webview.hostObjects.sync.eventForwarder.SendData(dataObj);
console.log(res);
}
In C# API:
using System;
using System.Runtime.InteropServices;
using System.Windows;
using Microsoft.Web.WebView2.Core;
namespace TestWebView2
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
InitializeAsync();
}
async void InitializeAsync()
{
await webView.EnsureCoreWebView2Async(null);
WebView_CoreWebView2Ready();
}
private void WebView_CoreWebView2Ready()
{
webView.CoreWebView2.AddHostObjectToScript("eventForwarder", new EventForwarder());
}
}
public class DataObject
{
public string nameX = "";
public string messageX = "";
public DataObject() { }
}
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
public class EventForwarder
{
public string SendData(DataObject data)
{
return "hasCall with parameters: " + data.nameX;
}
}
}
How can I receive the ObjectData on the API side as shown in the example above?
As described above, the example would not work because the following message comes back:
VM6:1 Uncaught (in promise) Error: Schnittstelle nicht unterst�tzt (0x80004002)
at RemoteMessenger.postSyncRequestMessage (<anonymous>:1:10471)
at Function.applyHostFunction (<anonymous>:1:22650)
at Object.apply (<anonymous>:1:15398)
at SendData (test.html:87)
at HTMLDivElement.onclick (test.html:93)
Thank for your answer
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.