@page "/" @inject IJSRuntime js <p> Open browser dev tools (F12) and select the console tab. Click the button to view test output. </p> <button @onclick="Test">Test</button> @code { async void Test() { var obj = await js.InvokeAsync<Object>("Read", 100); await js.InvokeAsync<Object>("Write", obj); } }
namespace BlazorFiddleProject { using Microsoft.AspNetCore.Components.Builder; using Microsoft.Extensions.DependencyInjection; public class Startup { public void Configure(IComponentsApplicationBuilder app) { app.AddComponent<App>("app"); } } }
<!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <meta name="viewport" content="width=device-width"> </head> <body> <app>Loading...</app> <script src="_framework/blazor.webassembly.js"></script> <script> // Test script let globalObj = { value: null, number: 100, string: "Hello World", date: new Date(), array: [1,2,3,4,5], fn: function() { } }; function Read(value) { globalObj.value = value; console.log("Read:", globalObj); return globalObj; } function Write(obj) { console.log("Write:", (obj === globalObj), obj); } </script> </body> </html>

Add component

BlazorFiddle was updated from Blazor 0.7 to .NET 6.0. Your old source code could not work. You need to upgrade to latest.