IvanJosipovic / BlazorApplicationInsights

Application Insights for Blazor web applications

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Gracefully handle lack of App Insights (due to adblocker, etc)

50Wliu opened this issue · comments

Most ad blockers out there block telemetry scripts like AI. This package should gracefully handle the case where App Insights is blocked or otherwise couldn't be loaded and do nothing, rather than throwing (user-visible) errors on every page load, e.g.:

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: appInsights is not defined
      ReferenceError: appInsights is not defined
          at Object.setInstrumentationKey (https://localhost:5001/_content/BlazorApplicationInsights/JsInterop.js:71:9)

Hey,
I do have tests for when AI is blocked,

public async Task TestBlocked(string id)

In my quick testing, running this function with AI blocked doesn't cause any issues. The AI JS snippet creates the "appInsights" objects and it should be available if AI is blocked.

Are you missing the JS snippet in the index.html?

Ooooh, you're right. No, right now we're actually including the script directly rather than using the snippet because of #1742. Sorry for the false alarm!