Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when starting in debug #5

Closed
mark-at-tusksoft opened this issue Aug 3, 2020 · 4 comments
Closed

Exception when starting in debug #5

mark-at-tusksoft opened this issue Aug 3, 2020 · 4 comments

Comments

@mark-at-tusksoft
Copy link

mark-at-tusksoft commented Aug 3, 2020

My implementation is almost verbatim for the example. Only major difference is that my App.razor is wrapped in a <CascadingAuthenticationState> component and the <ApplicationInsightsComponent> is outside of it.
Microsoft.JSInterop.JSException: Could not find 'appInsights' in 'window'.

If I reload the page, the error goes away.

@IvanJosipovic
Copy link
Owner

The error is saying that the JS Interop can't find the appInsights JavaScript object.
Have you added the JS snippet to the index.html?

Example,

@mark-at-tusksoft
Copy link
Author

Yes, as mentioned, it does work if I reload the page.

@IvanJosipovic
Copy link
Owner

I just checked one of my work projects which uses auth. I am not seeing the same issue that you're experiencing.

Here is the App.razor

<CascadingAuthenticationState>
    <CascadingBlazoredModal>
        <Router AppAssembly="@typeof(Program).Assembly">
            <Found Context="routeData">
                <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
                    <NotAuthorized>
                        @if (!context.User.Identity.IsAuthenticated)
                        {
                            <RedirectToLogin />
                        }
                        else
                        {
                            <p>You are not authorized to access this resource.</p>
                        }
                    </NotAuthorized>
                </AuthorizeRouteView>
            </Found>
            <NotFound>
                <LayoutView Layout="@typeof(MainLayout)">
                    <p>Sorry, there's nothing at this address.</p>
                </LayoutView>
            </NotFound>
        </Router>
    </CascadingBlazoredModal>
</CascadingAuthenticationState>
<ApplicationInsightsComponent />

I wonder if this is a timing issue. Can you please edit your JS snippet and set the ld parameter to -1.

ld: -1, // Defines the load delay (in ms) before attempting to load the sdk. -1 = block page load and add to head. (default) = 0ms 

@IvanJosipovic
Copy link
Owner

I had this issue happen to me, I tested with ld = -1 and it hasn't reoccurred. I have updated the installation guidance in the readme. Let me know if you see this issue again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants