Skip to content

[Problem/Bug]: Additional Objects passed using the WebMessageObjects API are null #5227

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

Open
DerPate2010 opened this issue May 2, 2025 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@DerPate2010
Copy link

DerPate2010 commented May 2, 2025

What happened?

I'm trying to get the full filesystem path of a FileSystemDirectoryHandle selected in the hosted web app. I followed the examples provided in the spec document.
#3706

Observed behavior:
The AddionalObjects Array on the receiving side is empty or contains null entries.

Expected behavior:
AdditionalObjects contains the corresponding WebView2 or FileSystem API objects

The customer context is the modernization of a legacy app. The scenario requires offline access to files retrieved via a legacy authentication system that requires native code. All business logic and file operations are implemented as a modern PWA. The use case that requires the shared FileHandles is about opening the local files in the installed desktop application (Word, Excel, PowerPoint)

Importance

Important. My app's user experience is significantly compromised.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

136.0.3240.50

SDK Version

1.0.2903.40

Framework

WinUI3/WinAppSDK

Operating System

Windows 11

OS Version

26100.3915

Repro steps

From Web to Native

JS code

          const dirHandle2 = await window.showDirectoryPicker({ mode: "readwrite" });
          const fileHandle2: FileSystemFileHandle = await dirHandle2.getFileHandle(this.doc!.name, {create:true});
          const additionalObjects:ArrayLike<object> =  [dirHandle2, fileHandle2];
          (<any>window).chrome.webview.postMessageWithAdditionalObjects ("getdldir", additionalObjects);

CS code

        private void CoreWebView2_WebMessageReceived(CoreWebView2 sender, CoreWebView2WebMessageReceivedEventArgs args)
        {
            var firstObject = args.AdditionalObjects[0];
            //is null
         }

Image

From Native to Web

JS code

       (<any>window).chrome.webview.addEventListener('message', async (arg:any) => {
            console.log(arg);
            //additionalObjects is an empty array
       }

CS code

            var fsHandle = AppWebView.CoreWebView2.Environment.CreateWebFileSystemDirectoryHandle("C:\\...\\App Docs", CoreWebView2FileSystemHandlePermission.ReadWrite);
            var fsHandle2 = AppWebView.CoreWebView2.Environment.CreateWebFileSystemFileHandle("C:\\...\\App Docs\\MFA is here.docx", CoreWebView2FileSystemHandlePermission.ReadWrite);
            AppWebView.CoreWebView2.PostWebMessageAsJson("{\"test\" : 0}", new List<object> { fsHandle, fsHandle2} );

Image

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

@DerPate2010 DerPate2010 added the bug Something isn't working label May 2, 2025
@sivMSFT
Copy link

sivMSFT commented May 6, 2025

Hi @DerPate2010, thank you reaching out.

For the most accurate and up-to-date information, I recommend referring to the official WebView2 Documentation. The GitHub spec-docs provide a great starting point and historical context.

Regarding your issue, the AdditionalObjects is now deprecated. Instead, you can use the CoreWebView2.PostWebMessageAsJson Method as an Alternative. Let us know, if you have any queries.

@DerPate2010
Copy link
Author

@sivMSFT
Thanks for providing the links. None of the documented APIs is working

@dhveerap
I added 5 examples to the WebView2Samples WinUI3 project. All of them are failing

Fork WebView2Samples Branch bug-5051

The customer context is the modernization of a legacy app. The scenario requires offline access to files retrieved via a legacy authentication system that requires native code. All business logic and file operations are implemented as a modern PWA. The use case that requires the shared FileHandles is about opening the local files in the installed desktop application (Word, Excel, PowerPoint)

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

3 participants