remibou / browserinterop Goto Github PK
View Code? Open in Web Editor NEWWrapper for Browser JS API for Blazor and JSInterop
License: MIT License
Wrapper for Browser JS API for Blazor and JSInterop
License: MIT License
I can't run geolocation on android chrome (ver. 86.0.4240.198). Dotnet 5.0
var window = await jsRuntime.Window();
var navigator = await window.Navigator(); //error line
Android firefox is OK. Can anyone check it out?
fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
Unhandled exception in circuit '3jXC60Frj0Yr97Nesw5jzNAZn8pqDWoTx22ACo9osDo'.
Microsoft.JSInterop.JSException: An exception occurred executing JS interop: The JSON value could not be converted to System.Double. Path: $.connection.downlinkMax | LineNumber: 0 | BytePositionInLine: 267.. See InnerException for more details.
---> System.Text.Json.JsonException: The JSON value could not be converted to System.Double. Path: $.connection.downlinkMax | LineNumber: 0 | BytePositionInLine: 267.
---> System.InvalidOperationException: Cannot get the value of a token type 'String' as a number.
at System.Text.Json.Utf8JsonReader.TryGetDouble(Double& value)
at System.Text.Json.Utf8JsonReader.GetDouble()
at System.Text.Json.Serialization.Converters.DoubleConverter.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
at System.Text.Json.JsonPropertyInfo1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader) at System.Text.Json.Serialization.Converters.ObjectDefaultConverter
1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.JsonConverter1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value) at System.Text.Json.JsonPropertyInfo
1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)
at System.Text.Json.Serialization.Converters.ObjectDefaultConverter1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value) at System.Text.Json.Serialization.JsonConverter
1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.JsonConverter1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) --- End of inner exception stack trace --- at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, Utf8JsonReader& reader, Exception ex) at System.Text.Json.Serialization.JsonConverter
1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.Serialization.JsonConverter`1.ReadCoreAsObject(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.JsonSerializer.ReadCore[TValue](JsonConverter jsonConverter, Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.JsonSerializer.ReadValueCore[TValue](JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& state)
at System.Text.Json.JsonSerializer.Deserialize(Utf8JsonReader& reader, Type returnType, JsonSerializerOptions options)
at Microsoft.JSInterop.JSRuntime.EndInvokeJS(Int64 taskId, Boolean succeeded, Utf8JsonReader& jsonReader)
--- End of inner exception stack trace ---
at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args)
at BrowserInterop.Extensions.BrowserInteropJsRuntimeExtension.GetInstanceProperty[T](IJSRuntime jsRuntime, JsRuntimeObjectRef jsObjectRef, String propertyPath, Object serializationSpec)
at BrowserInterop.Extensions.BrowserInteropJsRuntimeExtension.GetInstancePropertyWrapper[T](IJSRuntime jsRuntime, JsRuntimeObjectRef jsObjectRef, String propertyPath, Object serializationSpec)
at BrowserInterop.WindowInterop.Navigator()
at HAWebClient.Pages.Test.GetGeolocation() in C:\projekty\HolyAttendanceMobile\HAWebClient\HAWebClient\Pages\Test.razor:line 32
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)
These attributes are in decimal. Why not double? it would be the most suitable type.
That code can be executed not correctly:
protected override async Task OnInitialized()
{
var window = await jsRuntime.Window();
}
In that case, you will get the error:
JavaScript interop calls cannot be issued at this time. This is because the component is being statically rendererd. When prerendering is enabled, JavaScript interop calls can only be performed during the OnAfterRenderAsync lifecycle method.
In most cases, it can be easily solved when we will move that to another method that is executed later.
Dependabot couldn't find a .(cs|vb|fs)proj for this project.
Dependabot requires a .(cs|vb|fs)proj to evaluate your project's current .NET dependencies. It had expected to find one at the path: /<anything>.(cs|vb|fs)proj
.
If this isn't a .NET project, or if it is a library, you may wish to disable updates for it from within Dependabot.
On firefox I have endless console error logs about this, the interested section in the script.js
is at the line 183:
for (var i in data) {
var currentMember = data[i]; // <- This line
if (typeof currentMember === 'function' || currentMember === null) {
continue;
}
//...
}
Can you figure out how to make it scream this log?
I am trying to recover my GPS position and receive these alerts from the chrome browser.
scripts.js:183 [Deprecation] 'window.webkitStorageInfo' is deprecated. Please use 'navigator.webkitTemporaryStorage' or 'navigator.webkitPersistentStorage' instead.
scripts.js:238 [Violation] Only request geolocation information in response to a user gesture.
Uncaught ReferenceError: DotNet is not defined
at new <anonymous> (scripts.js:29)
at scripts.js:2
I am using .NET 5. Maybe it is the reason for the error.
Hi
I'm using net5.0 and I'm trying the code in
https://visualstudiomagazine.com/articles/2020/09/08/blazor-pwa-local-storage.aspx?admgarea=features
I've verified that I get Navigator.OnLine does not update: permanently returns the same value when the page is refreshed.
OnOnline and OnOffline events (WindowInterop) works perfectly.
Tnx
Hi,
I am interesting in using your library also as technology to wrap custom JavaScript library, because you already have all needed functionality as container for storing JavaScript object and so on ...
Is there example how to do this ?
The Window page in the sample app throws a JSON error (Chrome 84).
The properties in WindowVisualViewPort needs to be changed to doubles.
Validate at least locally that the E2E test passes on FF
Here I track progress on public API review
Here I track the documentation progress toward v1 release
This issue is here for tracking document API that will be wrapped. The purpose is to target all API that provide informations not already available in Blazor
Item for tracking progress on window event wraping. Here is the list of event I plan on implementing :
Documentation https://developer.mozilla.org/en-US/docs/Web/API/Window#Events
When I dispose my JsObjectWrapperBase
-derived object in the DisposeAsync
of a component, I get an exception that JsRuntime
is null. The problem is from there:
public class JsRuntimeObjectRef : IAsyncDisposable
{
internal IJSRuntime JsRuntime { get; set; }
[JsonPropertyName("__jsObjectRefId")]
public int JsObjectRefId { get; set; }
public async ValueTask DisposeAsync()
{
JsRuntimeObjectRef runtimeObjectRef = this;
// HERE: runtimeObjectRef.JsRuntime is null in the next line
await JSRuntimeExtensions.InvokeVoidAsync(runtimeObjectRef.JsRuntime, "browserInterop.removeObjectRef", new object[1]
{
(object) runtimeObjectRef.JsObjectRefId
}).ConfigureAwait(false);
GC.SuppressFinalize((object) runtimeObjectRef);
}
}
Not sure what might be causing this, it's not null in the object itself, so I added this method to my object:
public new async ValueTask DisposeAsync()
{
// NOTE: For some reason JsObjectRef's JsRuntime is null in DisposeAsync, so this is copied from there
await JsRuntime.InvokeVoidAsync("browserInterop.removeObjectRef", new object[1]
{
JsObjectRef.JsObjectRefId
});
GC.SuppressFinalize(JsObjectRef);
GC.SuppressFinalize(this);
}
I'm using Blazor WASM 6.0.6 on .NET 6.
It would be nice to add WebRTC API ...
Actually, I even can help with adding this API to your project if you do not mind ?
Hi,,
It would be nice to have possibility to return value from CallBackInteropWrapper
like ValueTask<TResult>
In the code the casing of SetJSRuntime is inconsistent mixture of SetJSRuntime/SetJsRuntime; please consider using consistent casing and/or using an interface/abstract class to enforce the standard.
It would be nice to have ability to access DOM elements and based on this API could be written lots of C# Blazor UI Libraries
@RemiBou Recently I have created small library that simplify Razor Class Library dependency management
https://github.com/redradist/BlazorDependencies
https://medium.com/@redradist/blazor-dependencies-d5597d07ebef
Using it user may not to manually add all script dependencies to index.hmtl ;)
First of all, thanks for your efforts. I like if someone puts effort into making JS Interop more easy to use.
I didn't find any possibility to invoke a constructor of a class. Is that feature missing?
i found Error: Microsoft.JSInterop.JSException: Could not find 'browserInterop' in 'window'.
Error: Could not find 'browserInterop' in 'window'.
On linux server.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.