Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
josephsobhy opened this issue Jul 2, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@josephsobhy
Copy link

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 josephsobhy added the bug Something isn't working label Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant