Skip to content

[Wasm] WebView.executeScriptAsync must be a Function but was undefined #19635

Closed
@jeromelaban

Description

@jeromelaban

I haven't seen this anywhere and, before filing a but report, I wanted to ask if ExecuteScriptAsync() is available for the WASM implementation of WebView2? When I try it ...

                try
                {
                    await WebView.ExecuteScriptAsync("document.getElementById('test').style.color = 'red';");
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"EXCEPTION: [{ex}] [{ex.StackTrace}]");
                }

... I get the following (and more) in the JavaScript console:

EXCEPTION: [Error: globalThis.Microsoft.UI.Xaml.Controls.WebView.executeScriptAsync must be a Function but was undefined
dotnet.native.8bti36lthm.js:8     at http://localhost:5000/_framework/dotnet.runtime.tsg4gsv2hg.js:3:170299
dotnet.native.8bti36lthm.js:8     at http://localhost:5000/_framework/dotnet.runtime.tsg4gsv2hg.js:3:170373
dotnet.native.8bti36lthm.js:8     at Fc (http://localhost:5000/_framework/dotnet.runtime.tsg4gsv2hg.js:3:171729)
dotnet.native.8bti36lthm.js:8     at wasm://wasm/00b59456:wasm-function[287]:0x1f0c7
dotnet.native.8bti36lthm.js:8     at wasm://wasm/00b59456:wasm-function[218]:0x1c7c6
dotnet.native.8bti36lthm.js:8     at wasm://wasm/00b59456:wasm-function[209]:0xea13
dotnet.native.8bti36lthm.js:8     at wasm://wasm/00b59456:wasm-function[246]:0x1d33e
dotnet.native.8bti36lthm.js:8     at wasm://wasm/00b59456:wasm-function[3221]:0xf0ea8
dotnet.native.8bti36lthm.js:8     at wasm://wasm/00b59456:wasm-function[2544]:0xc69fe
dotnet.native.8bti36lthm.js:8     at wasm://wasm/00b59456:wasm-function[2549]:0xc71f6] [   at System.Runtime.InteropServices.JavaScript.JSFunctionBinding.BindJSImportImpl(String functionName, String moduleName, ReadOnlySpan`1 signatures)
dotnet.native.8bti36lthm.js:8    at System.Runtime.InteropServices.JavaScript.JSFunctionBinding.BindJSFunction(String functionName, String moduleName, ReadOnlySpan`1 signatures)
dotnet.native.8bti36lthm.js:8    at __Microsoft.UI.Xaml.Controls.NativeWebView.NativeMethods.ExecuteScript(IntPtr htmlId, String script) in /agent/_work/1/s/src/Uno.UI/obj/Uno.UI.Wasm/Release/net9.0/Microsoft.Interop.JavaScript.JSImportGenerator/Microsoft.Interop.JavaScript.JSImportGenerator/JSImports.g.cs:line 298
dotnet.native.8bti36lthm.js:8    at Microsoft.UI.Xaml.Controls.NativeWebView.ExecuteScriptAsync(String script, CancellationToken token) in /agent/_work/1/s/src/Uno.UI/UI/Xaml/Controls/WebView/Native/Wasm/NativeWebView.wasm.cs:line 51
dotnet.native.8bti36lthm.js:8    at Microsoft.Web.WebView2.Core.CoreWebView2.<>c__DisplayClass160_0.<ExecuteScriptAsync>b__0(CancellationToken ct) in /agent/_work/1/s/src/Uno.UI/UI/Xaml/Controls/WebView/Core/CoreWebView2.cs:line 141
dotnet.native.8bti36lthm.js:8    at Windows.Foundation.AsyncOperation.<>c__DisplayClass2_0`1[[System.String, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].<FromTask>b__0(CancellationToken ct, AsyncOperation`1 _) in /agent/_work/1/s/src/Uno.Foundation/Internal/AsyncOperation.cs:line 15
dotnet.native.8bti36lthm.js:8    at Windows.Foundation.AsyncOperation`1.<BuildTaskAsync>d__23[[System.String, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext() in /agent/_work/1/s/src/Uno.Foundation/Internal/AsyncOperation.TResult.cs:line 83
dotnet.native.8bti36lthm.js:8    at System.WindowsRuntimeSystemExtensions.<AsTaskCore>d__11`1[[System.String, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext() in /agent/_work/1/s/src/Uno.UWP/System.Runtime/WindowsRuntimeSystemExtensions.cs:line 66
dotnet.native.8bti36lthm.js:8    at UnoResourceLoadingTest.MainPage.NavWebViewButton_Click(Object sender, RoutedEventArgs e) in C:\Users\ben\RiderProjects\UnoResourceLoadingTest\UnoResourceLoadingTest\MainPage.xaml.cs:line 124]

Happens with any Uno.Sdk 5.6.xx implementation I've tried, both in VisualStudio Windows and JetBrains Rider for MacOS.

Originally posted by @baskren in #19627

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions