WebView2Feedback icon indicating copy to clipboard operation
WebView2Feedback copied to clipboard

[Problem/Bug]: Windows.Storage.Streams.Buffer length is always zero in WebView2

Open josephsobhy opened this issue 1 year ago • 0 comments

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

josephsobhy avatar Jul 02 '24 13:07 josephsobhy