BlazorApplicationInsights icon indicating copy to clipboard operation
BlazorApplicationInsights copied to clipboard

♻️ Init - UpdateCfg - Try catch

Open MattParkerDev opened this issue 1 year ago • 5 comments

A Content Security Policy or ad blocker may block downloading the ai.3.gbl.min.js file, but the init proceeds regardless. It will cause the dreaded red blazor error bar if the js file hasn't been downloaded. End users don't need to see an error here, so lets try catch, and log the error if one occurs, rather than leaving the exception unhandled.

MattParkerDev avatar Aug 29 '24 09:08 MattParkerDev

~~A try/catch should be added into the project in some capacity. Errors from simply having an Adblocker need to be squelched...~~ Preventing unwanted requests/exceptions when an adblocker is present sounds great to me, but ~~applying it here in this manner~~ this change seems like it would paper-over https://github.com/IvanJosipovic/BlazorApplicationInsights/issues/287

There seems to be a race condition where appInsights.updateCfg() is being called/invoked before the module has finished loading. This PR would obscure that issue, by suggesting "it didn't work because you have an adblocker" when in reality... there may be a race-condition that's happening instead.

karlapsite avatar Aug 29 '24 15:08 karlapsite

This library has tests that check that no errors occur in an Adblock situation, see here: https://github.com/IvanJosipovic/BlazorApplicationInsights/blob/bd5f6bafcb5d0f749aa79d8746bb4b2a3e062a3b/tests/BlazorApplicationInsights.Tests/UnitTests.cs#L608

I think the root cause is https://github.com/IvanJosipovic/BlazorApplicationInsights/issues/287 and should be resolved, I don't have time at the moment to resolve it.

IvanJosipovic avatar Aug 29 '24 20:08 IvanJosipovic

It's always a pleasure to see tests like this! My comment was based on some behavior I was chasing down today related to this exception. It sounds like we're in agreement that sorting through what may be a race-condition sounds a bit troublesome... or a headache... or both.

As far as the comment on how this library plays with adblockers... My words came from a half-baked thought: "I think it's a little odd to see the library continue to send track requests when presumably nothing should have loaded."

I made an edit to hopefully clarify slightly.

if we could detect the presence of an adblocker (if something failed to load) It'd be convenient to help keep the noise down in the network tab (which might be close to what this PR may have been trying to get at)

karlapsite avatar Aug 30 '24 00:08 karlapsite

But the appInsights.updateCfg() javascript function lives in the ai.3.gbl.min.js file, so to me seems unrelated to the BlazorApplicationInsights.lib.module.js module being loaded?

The only case when the #287 would occur, is when the ai.3.gbl.min.js file hasn't been loaded yet/blocked?

Additionally, regarding the playwright test you pointed out, this test does not actually test what happens if the ai.3.gbl.min.js script cannot be loaded, as the script loader falls back to ~7 cdn urls, attempting to get the script. image

Here's the extreme case where the fallback URLs are being blocked by a CSP: image

MattParkerDev avatar Aug 30 '24 02:08 MattParkerDev

@IvanJosipovic is there any update on this? :)

MattParkerDev avatar Sep 09 '24 03:09 MattParkerDev

:tada: This PR is included in version 3.2.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

github-actions[bot] avatar Jun 04 '25 05:06 github-actions[bot]