Closed emre-ozgu closed 4 weeks ago
Thanks for reporting this issue! ReadBytes has one out
parameter and since JavaScript doesn't support out parameters wv2winrt turns that into a return value (see more info on how wv2winrt handles out parameters) - which you figured out from looking at the generated code. So it should be dataReader.readBytes()
like you have, but it should be giving you a JavaScript array of the bytes of the file and not an empty array. I've filed a bug to track this, thanks!
Any update on this @david-risney ? It is blocking us from implementing some critical functionality in a webview2 app.
Unfortunately no update yet. You may be able to workaround the issue by creating your own WinRT runtimeclass with method to operate on the data reader or return the values you need with a different type.
This is now fixed in edge 126 and webview2 sdk 1.0.2535.41.
you'll need to set the host objects option for chrome.webview.hostObjects.options.shouldPassTypedArraysAsArrays to true.
Also readBytes
is not returning the result not the passed out param.
Please feel free to resolve.
Thanks for confirming @josephsobhy!
Description The documentation for
DataReader.ReadBytes
(https://learn.microsoft.com/en-us/uwp/api/windows.storage.streams.datareader.readbytes?view=winrt-22621) shows that we need to pass an array that will store the bytes that are read. This is how we were using it on WebView1 from JavaScript as well.On WebView2, calling this method in the same way from JavaScript throws an
Invalid number of parameters. 0x8002000E
error.Version WebView2 Version: 1.0.1777-prerelease Framework: UWP, WinRT OS: Win10
Repro Steps:
Output:
Additional Context
If I'm understanding the
Windows.Storage.Streams.g.cpp
file generated fromwv2winrt
correctly, this seems to expect no parameters despite the documentation:else { hr = DISP_E_BADPARAMCOUNT; }
Windows.Storage.FileIO.ReadBufferAsync(file) .then((buffer) => { const dataReader = Windows.Storage.Streams.DataReader.FromBuffer(buffer); console.log(dataReader.readBytes()); });
[]