Soenneker.Blazor.Utils.JsVariable
4.0.1361
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.Blazor.Utils.JsVariable --version 4.0.1361
NuGet\Install-Package Soenneker.Blazor.Utils.JsVariable -Version 4.0.1361
<PackageReference Include="Soenneker.Blazor.Utils.JsVariable" Version="4.0.1361" />
<PackageVersion Include="Soenneker.Blazor.Utils.JsVariable" Version="4.0.1361" />
<PackageReference Include="Soenneker.Blazor.Utils.JsVariable" />
paket add Soenneker.Blazor.Utils.JsVariable --version 4.0.1361
#r "nuget: Soenneker.Blazor.Utils.JsVariable, 4.0.1361"
#:package Soenneker.Blazor.Utils.JsVariable@4.0.1361
#addin nuget:?package=Soenneker.Blazor.Utils.JsVariable&version=4.0.1361
#tool nuget:?package=Soenneker.Blazor.Utils.JsVariable&version=4.0.1361
Soenneker.Blazor.Utils.JsVariable
A scoped Blazor interop service for checking whether a globalThis property exists and waiting for a script-created global to become available.
Use it when integrating a third-party script that exposes readiness only by assigning a global object. Prefer the script’s documented load event or initialization promise when one exists.
Installation
dotnet add package Soenneker.Blazor.Utils.JsVariable
using Soenneker.Blazor.Utils.JsVariable.Registrars;
builder.Services.AddJsVariableInteropAsScoped();
@using Soenneker.Blazor.Utils.JsVariable.Abstract
@inject IJsVariableInterop JsVariables
The checks require browser interop, so call them after interactive rendering rather than during server prerendering.
Check once
bool mapsReady = await JsVariables.IsVariableAvailable("google.maps");
Paths are dot-separated and resolved from globalThis. Every segment must be an own data property. Prototype traversal and accessor execution are deliberately excluded, so inherited properties and getter-only globals are reported as unavailable.
A property whose value is null counts as available. A missing property or one whose value is JavaScript undefined does not.
Wait with a timeout
try
{
await JsVariables.WaitForVariable(
"google.maps",
delay: 25,
timeout: 5_000,
cancellationToken);
// The global existed at the end of the wait. Use the owning SDK here.
}
catch (TimeoutException)
{
// The script did not expose the global within five seconds.
}
delay and timeout are milliseconds. Delay must be greater than zero; timeout can be zero for an immediate check. With no timeout, the wait continues until the value appears, cancellation is requested, or the scoped service is disposed.
Each wait has independent timer state. Cancellation clears its browser timer, settles the pending JavaScript promise, and propagates OperationCanceledException. A timeout is surfaced as TimeoutException.
Availability is only a point-in-time observation. Another script can replace or remove the property immediately afterward, so the subsequent SDK call must still handle its own errors.
Path and trust guidance
Use paths defined by the application or SDK documentation. Empty path segments and __proto__, prototype, or constructor segments are rejected.
Do not use global-variable availability as proof that a script is trustworthy, that a user is authorized, or that an SDK response is safe. Any script running in the page can create or replace globals, and values received from JavaScript still require validation.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Soenneker.Blazor.Utils.Ids (>= 4.0.22)
- Soenneker.Blazor.Utils.ModuleImport (>= 4.0.1859)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Soenneker.Blazor.Utils.JsVariable:
| Package | Downloads |
|---|---|
|
Soenneker.Blazor.Utils.ResourceLoader
A Blazor JavaScript interop for dynamically loading scripts, styles, and modules |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.1363 | 0 | 8/30/2026 |
| 4.0.1362 | 0 | 8/30/2026 |
| 4.0.1361 | 0 | 8/30/2026 |
| 4.0.1359 | 21 | 8/29/2026 |
| 4.0.1358 | 27 | 8/29/2026 |
| 4.0.1357 | 38 | 8/29/2026 |
| 4.0.1356 | 1,209 | 8/26/2026 |
| 4.0.1355 | 421 | 8/26/2026 |
| 4.0.1354 | 2,543 | 8/21/2026 |
| 4.0.1353 | 2,653 | 8/18/2026 |
| 4.0.1352 | 1,864 | 8/13/2026 |
| 4.0.1351 | 720 | 8/12/2026 |
| 4.0.1350 | 3,142 | 8/9/2026 |
| 4.0.1349 | 1,616 | 8/8/2026 |
| 4.0.1348 | 583 | 8/8/2026 |
| 4.0.1347 | 2,925 | 8/7/2026 |
| 4.0.1346 | 2,494 | 7/29/2026 |
| 4.0.1345 | 2,148 | 7/29/2026 |
| 4.0.1344 | 337 | 7/28/2026 |
| 4.0.1343 | 402 | 7/28/2026 |
Update dependency Soenneker.Blazor.Utils.Ids to 4.0.22 (#1916)