IvanJosipovic / BlazorApplicationInsights

Application Insights for Blazor web applications

Home Page:https://BlazorApplicationInsights.netlify.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FireFox: Could not find 'appInsights.updateCfg' ('updateCfg' was undefined).

KrzychuR opened this issue · comments

Hi,
Thanks for effort to nicely integrate Application Insights into Blazor!

I'm facing issue with SDK load (I think) randomly, is hard to reproduce it as it happens let's say 1/10 calls in FireFox. I cannot reproduce it under Chrome.

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Could not find 'appInsights.updateCfg' ('updateCfg' was undefined).
      findFunction/<@https://localhost:7281/_framework/blazor.webassembly.js:1:368
(...)

Any clue how to narrow it, what to check? I've read docs many times already to double check if everything is correctly set. My app is standalone WASM. AppInsights loader script is in 'head' with ld: -1 option. Is it possible that FF doesn't wait for script load as described here ?

I'm having this issue quite consistently after upgrading to the latest version. Have double and triple-checked all the config. Using Chrome.
Issue occurs during the Authentication redirects, but only when running the WASM App from Visual Studio.
Running the WASM App from the command line does not reproduce this issue. Also does not seem to impact the application once it's deployed.

Have subscribed and will keep working on issue (though it's not our highest priority right now since it's only marginally effecting developer experience). Will post back if I figure anything out.

I'm also running into this issue using the Standalone wasm code. Also the same, it occurs after the authentication redirect from Microsoft. Error is happening for me using Microsoft Edge

not sure if this is the actual cause, but it appears for WASM, the lib.module.js file is auto executed by Blazor due to its name. But then the .js file is manually loaded again. And if it doesn't happen fast enough, seems this error is encountered and why it's so random.

await JSRuntime.InvokeAsync<IJSObjectReference>("import", "./_content/BlazorApplicationInsights/BlazorApplicationInsights.lib.module.js");

I'm going to clone the repository and remove that and see if it changes anything.

OK, forked the code base and removed the redundant call to load the script but the error persists. not sure why...

I have the same Issue with the next setup:

  • Blazor .Net 8.0 / WebAssembly

The issue is totally random, but usually happen in Chrome with the next error:

Issue

blazor.webassembly.js:1 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Could not find 'appInsights.updateCfg' ('updateCfg' was undefined).
Error: Could not find 'appInsights.updateCfg' ('updateCfg' was undefined).

Hey folks, apologies for the delay in looking into this.

This issue is related to the Application Insights snippet. I could reproduce this issue by running the tests until they fail.

I'm starting to feel that this is a bug with Application Insights as it doesn't appear to be blocking while its loading.

Just installed this for the first time and getting the same issue in Edge. What is the current work around while a more permanent solution is developed?

Just installed this for the first time and getting the same issue in Edge. What is the current work around while a more permanent solution is developed?

For now, the manual approach should work as normal, https://github.com/IvanJosipovic/BlazorApplicationInsights?tab=readme-ov-file#install-on-blazor-webassembly-standalone-app---manual

I tried the Blazor Webassemlby standalone app manual guide with nugget version 3.1.0 but I got an exception on Edge:

Error: Could not resolve type with token 01000024 from typeref (expected class 'BlazorApplicationInsights.Models.Config' in assembly 'BlazorApplicationInsights, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null')

I could be wrong but I think this screenshot explains the error:

image

In case of wasm standalone, this issue happens because the script injected in index.html loads https://js.monitor.azure.com/scripts/b/ai.3.gbl.min.js.
It is not one of the service worker assets, it is not cached for the offline use.
See on the screenshot above it loads from the disk cache, not from ther service worker assets.

To reproduce this issue, stable steps are: open the chrome developer console, go to Network, check "Disable cache" (otherwise the browser will return this file from cache even when offline, and there will be a race condition) and "Offline" (to disable it loading).

Screenshot 2024-06-15 050347

So when working offline, the BlazorApplicationInsights calls the appInsights.updateCfg which is not ready yet (depending on the browser cache performance. Which may even get expired, by the way, as opposed to the web worker's cache storage).

The workaround that I did was saving the ai.3.gbl.min.js file to the blazor wwwroot folder, selecting Build Action = Content, and referencing it from the script in the index.html directly:
image

This way, it works. On publish, it appears in the service worker assets:
image

I haven't checked the Install on Blazor WebAssembly Standalone App - Manual section, though.

Also experiencing this issue after upgrading on all browsers. Currently sticking to the previous version works.