Tracking code overrides window.onerror


I was trying to setup an integration with an error reporting service for our site earlier today that I was hitting issues with, and I believe it’s because of an issue in the HubSpot tracking code that gets embedded into the site. The error reporting service we’re using relies on using the window.onerror function in JavaScript to receive events, but it appears that the HubSpot tracking code is overriding that.

Here’s the relevant snippet I’m seeing in the file that gets inserted by HubSpot:

window.onerror=function(e,o,i,l,s){o&&t(r,o)&&!t(a,s.message)&&"script error"!==e.toLowerCase()&&n._sendReport("error",e,o,i,l,s)}}

That snippet overrides window.onerror without delegating to the original handler, which messes up the error handler that the other plugin registers. Here’s an alternative solution that could help avoid this issue:

var oldOnError = window.onerror;
window.onerror = function() {
if(oldOnError) oldOnError.apply(this, arguments);	// Call any previously assigned handler
  // The rest of your code

Details on the solution are here:

Is there any way we can get you to either a) turn this behavior off or b) update the tracking code so we can work around this?