MicrosoftEdge / MicrosoftEdge/WebView2Feedback
[Problem/Bug]: Windows.Storage.Streams.Buffer length is always zero in WebView2
Open
@david-risney is already working on this.
Since Jul 16, 2024.
bug
- Dominant language
- PowerShell
- Stars
- 526
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
What happened?
Buffer.Length always return zero in webview2.
Same code in webview1 returns the correct value.
const Windows = chrome.webview.hostObjects.sync.Windows;
const capacity = 10;
const buffer = new Windows.Storage.Streams.Buffer(capacity);
console.log(buffer.length); // 0
A more practical example to read bytes from a file.
const appRootFolder = Windows.Storage.ApplicationData.current.localFolder;
await appRootFolder.createFileAsync('download.txt', Windows.Storage.CreationCollisionOption.openIfExists);
const file = await appRootFolder.getFileAsync('download.txt');
await Windows.Storage.FileIO.writeTextAsync(file, "abcdz");
Windows.Storage.FileIO.readBufferAsync(file)
.then((buffer) => {
const dataReader = Windows.Storage.Streams.DataReader.fromBuffer(buffer);
const bytes = new Uint8Array( buffer.length );
console.log(`Buffer length is ${buffer.length}`);
console.log(dataReader.readBytes(bytes));
// Manually reading the first 5 bytes instead of using buffer.length
const bytes2 = new Uint8Array( 5 );
console.log(dataReader.readBytes(bytes2));
});
Importance
Blocking. My app's basic functions are not working due to this issue.
Runtime Channel
Stable release (WebView2 Runtime)
Runtime Version
126.0.2592.81
SDK Version
1.0.2535.41
Framework
WinUI2/UWP
Operating System
Windows 10
OS Version
No response
Repro steps
const Windows = chrome.webview.hostObjects.sync.Windows;
const capacity = 10;
const buffer = new Windows.Storage.Streams.Buffer(capacity);
console.log(buffer.length); // 0
Repros in Edge Browser
No, issue does not reproduce in the corresponding Edge version
Regression
No, this never worked
Last working version (if regression)
No response
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.