A few days ago I faced with console error in the Blazor Webassembly .NET 7 application:
Microsoft.JSInterop.JSException: Converting circular structure to JSON --> starting at object with constructor 'Window' --- property 'window' closes the circle TypeError: Converting circular structure to JSON --> starting at object with constructor 'Window' --- property 'window' closes the circle at JSON.stringify () ... at Microsoft.JSInterop.JSRuntime.<InvokeAsync>d__16`1[[System.String, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
Browser console is all red with errors:
The issue was in the next error:
await JSRuntime.InvokeAsync<string>("open", $"{Navigation.BaseUri}{urlPart}/{id}", "_blank", "width = 766, height = 840, left = 200, top = 200");
This line is responsible for opening a new popup window in the browser. The problem was in InvokeAsync<string> because it tries to serialize the return value. Instead, you need to use InvokeVoidAsync. So the solution to the problem looks like this:
await JSRuntime.InvokeVoidAsync("open", $"{Navigation.BaseUri}{urlPart}/{message.MessageID}", "_blank", "width = 766, height = 840, left = 200, top = 200");
Just replace InvokeAsync<string> with InvokeVoidAsync 😉
You may also be interested to read my articles related to Blazor: