CORS error when capturing an Exception in Blazor WebAssembly App


I want to use Sentry in a Blazor WebAssembly (WASM) App. When I try to capture an exception with:
SentrySdk.CaptureException(new Exception("foo"));
i get a CORS error:

Quellübergreifende (Cross-Origin) Anfrage blockiert: Die Gleiche-Quelle-Regel verbietet das Lesen der externen Ressource auf<...>/store/. (Grund: CORS-Preflight-Antwort schlug fehl).

Quellübergreifende (Cross-Origin) Anfrage blockiert: Die Gleiche-Quelle-Regel verbietet das Lesen der externen Ressource auf<...>/store/. (Grund: CORS-Anschlag schlug fehl).

For the OPTIONS Request sent to the server the headers are as follows:

User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0
Accept: */*
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate, br
Access-Control-Request-Method: POST
Access-Control-Request-Headers: content-encoding,x-sentry-auth
Referer: http://localhost:62353/bar
Origin: http://localhost:62353
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache

When I remove the ‘content-encoding’ from the ‘Access-Control-Request-Headers’ and resend it from within Firefox DevTools the answer is 200 OK

AFAIK CORS is configured at the server. So I am out of ideas on what to do.

Is there anything I can do to make this work?


Thank you for you using Sentry and filing an issue.
I have had a look at the CORS problem and it seems to be on our side.
I am working on a fix right now and I expect it to be live by the end of the day.
I will post another message when it is.

Best regard,
Radu W.

1 Like

Thanks @RaduW for fixing this!

And thanks @QFood for trying the .NET SDK with Blazor web assembly. I’ve been wanting to take a look at that for a while now. Last I tried wasm didn’t have ‘threads’ but since then Mono already mapped Task.Run to the new threading so it should work now submitting events in the background.
Perhaps .NET 5 will release a stable version of Blazor wasm already.

Let us know how it works.

A fix is now live, @QFood please let us know if you experience any other problems.

1 Like

@RaduW A first quick Test was successful. Thanks, you are fantastic!

@bruno-garcia Blazor WASM is scheduled to be released in May. Currently Preview 2 is out.

That’s great news. I hope you can share you experiments with us so we can learn from it.
By any chance are you pushing the code to GitHub?

My goal is to log unhandled exceptions to Sentry. Currently (Blazor WASM preview 2) it is not possible as Blazor uses Console.WriteLine to display exceptions to the developer. This will be changed in Preview 3 to use an ILogger which can be plugged in by the developer.

Log unhandled exceptions to custom logger

Sounds good, I guess then Sentry.Extensions.Logging could be used.
I wonder also if SentrySdk.CaptureException(new Exception()); would work.

Yes, that was working.

1 Like