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

[BUG] window is not defined at _getStackFromErrorObj #2162

Closed
EvgenyWas opened this issue Sep 21, 2023 · 1 comment
Closed

[BUG] window is not defined at _getStackFromErrorObj #2162

EvgenyWas opened this issue Sep 21, 2023 · 1 comment

Comments

@EvgenyWas
Copy link

EvgenyWas commented Sep 21, 2023

Description/Screenshot
I connected the Application Insights JavaScript SDK to my Nuxt 3 app on both sides - server and client, and in my Application Insights events I see this log with the following message for the tracked exception value:
ReferenceError: window is not defined at _getStackFromErrorObj (/app/.output/server/node_modules/@microsoft/applicationinsights-web/dist/es5/applicationinsights-web.js:6331:22)

And in your code I found this line that causes this issue - link.

I understand it might be happening because I use the Application Insights package for the web and some methods might be executed during SSR, but it's a little bit annoying because this check for the existing window is not correct.

  • OS/Browser: windows x64
  • SDK Version [e.g. 22]: "@microsoft/applicationinsights-web": "^3.0.2"
  • How you initialized the SDK:
const appInsights = new ApplicationInsightsClient({
    config: {
      connectionString,
      enableAutoRouteTracking: true,
      autoTrackPageVisitTime: true,
      enableCorsCorrelation: true,
      enableUnhandledPromiseRejectionTracking: true,
      enableAjaxPerfTracking: true,
    },
  });

Expected behavior
There is no such a log in Application Insights tracked exceptions. The usage should be isomorphic or at least fault-tolerant for such cases.

Additional context
Thanks for your work and I will be glad to update this issue with more information for a speedy solution.

@MSNev
Copy link
Collaborator

MSNev commented Sep 21, 2023

While the code was created to "check" for the existence of window before using it, this is occurring because the runtime is complaining about the non-existence of the "global"

} else if (window && window["opera"] && errorObj[strMessage])

So we will need to change this to use the getWindow() helper which handles this scenario.

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

No branches or pull requests

3 participants