Tinkoff / micro-sentry

Tiny Sentry client with idiomatic wrapper for Angular
Apache License 2.0
118 stars 8 forks source link

[BUG] ReferenceError: XMLHttpRequest is not defined on SSR #41

Open renatoaraujoc opened 1 year ago

renatoaraujoc commented 1 year ago

🐞 Bug report

Description

Dispatching an error on server-side of Angular will error with XMLHttpRequest not defined.

Reproduction

No need to reproduce this, afaik XMLHttpRequest is not a defined in node environments.

Expected behavior

The library has to provide some sort of http-request api (to at least inform in the readme that we're supposed to provide it on the global window object) to report errors on server-side if its supposed to. Or completely ignore server-side errors and let the browser handle those as they implement the XMLHttpRequest object.

Versions

If needed:

Additional context

This is my server window object (necessary for lots of stuff to work): Screenshot 2023-04-10 at 11 40 29 This is the error: Screenshot 2023-04-10 at 11 36 41

renatoaraujoc commented 1 year ago

Hello,

Fixed it with:

import XMLHttpRequest from 'xhr2';
(global as any).XMLHttpRequest = XMLHttpRequest;

in server.ts.

I'm leaving this opened so you guys can maybe provide 'xhr2' as dependency, detect if XMLHttpRequest is present, if not, use this library.

It's up to you :)