I am struggling with the problem that I'm getting a lot of the exceptions in Azure Application Insights with this error message: Script error: The browser's same-origin policy prevents us from getting the details of this exception. Consider using the 'crossorigin' attribute.
I understand that I need to add crossorigin="anonymous" to the script tag, but the problem is that these errors are generated from Ads script (which also loads other scripts) on our site, so I can't actually put that attribute for all of them.
Basically I don't even care about these errors, so I just don't want to send them to the Application Insights at all. I've added the telementry initializer, which I expected will work to filter the errors, but I still receive a lot of that errors (~100.000 per day). Here is the initializer filtering I tried:
ai.addTelemetryInitializer((item) => {
if (item.baseType == "ExceptionData" && item.baseData &&
item.baseData.exceptions && item.baseData.exceptions.length > 0 &&
item.baseData.exceptions[0].message.startsWith("Script error:")) {
return false;
}
});
Also I've tried to filter it by item.baseData.error, but that also didn't help.
How should I configure the telemetry initializer so I can skip these errors?