raygun.min.js is breaking our window.onbeforeunload event handler

wpatter6

Posted on
Jun 23 2016

Hi, I am adding an event handler using jquery to the window.onbeforeunload event handler, like so:

$(window).bind("beforeunload", function () { console.log("before unload"); });

However, I have found that it seems the line in raygun.min.js file is overwriting the entire event and preventing our event handler from firing:

a.onbeforeunload=function(){var a=[];if(v(a),a.length>0){var b={eventData:[{sessionId:z.sessionId,timestamp:(new Date).toISOString(),type:"web_request_timing",user:z.user,version:z.version||"Not supplied",device:navigator.userAgent,data:JSON.stringify(a)}]};z.makePostCorsRequest(z.apiUrl+"/events?apikey="+encodeURIComponent(z.apiKey),JSON.stringify(b))}}

I went and changed the line to the following:

$(a).bind("beforeunload", function(){var a=[];if(v(a),a.length>0){var b={eventData:[{sessionId:z.sessionId,timestamp:(new Date).toISOString(),type:"web_request_timing",user:z.user,version:z.version||"Not supplied",device:navigator.userAgent,data:JSON.stringify(a)}]};z.makePostCorsRequest(z.apiUrl+"/events?apikey="+encodeURIComponent(z.apiKey),JSON.stringify(b))}})

and it now works properly. Of course, this required jquery to be loaded prior to the raygun.min.js file, and if any updates occur this change I made will be lost.

Is there something I'm missing here or a setting I need to set so your file will not break our event handler? Or do I need to remember to update this file by changing the above line any time an update occurs in raygun?


Callum

Posted on
Jun 28 2016

Thanks for reporting this; you're not missing anything as an additional guard will be need to be added to Raygun4JS to check for the presence of an existing beforeunload handler. I have noted this down and will add it in the next release.

Regards,

Callum Gavin
Raygun Limited


wpatter6

Posted on
Jun 29 2016

Thanks for the info, I'll keep my eyes out for the update


Callum

Posted on
Jul 07 2016

Hi again,

I've just had time to have a deeper dive into this, the bug is present in your version, v2.1.0, but was fortunately fixed in v2.2.0. I'm just deploying a new version of the provider shortly, v2.3.4, but if you upgrade to the latest version your beforeunload handler won't be overwritten as expected.

Regards,

Callum Gavin
Raygun Limited


Reply