Raygun is not defined
Anders
Posted on
Mar 05 2016
Hi
In some cases we get Raygun is not defined when trying to report javascript errors. The code is initiated with :
$(document).ready(function () { try { !function (a, b, c, d, e, f, g, h) { a.RaygunObject = e, a[e] = a[e] || function () { (a[e].o = a[e].o || []).push(arguments); }, f = b.createElement(c), g = b.getElementsByTagName(c)[0], f.async = 1, f.src = d, g.parentNode.insertBefore(f, g), h = a.onerror, a.onerror = function (b, c, d, f, g) { h && h(b, c, d, f, g), g || (g = new Error(b)), a[e].q = a[e].q || [], a[e].q.push({ e: g }); }; }(window, document, "script", "//cdn.raygun.io/raygun4js/raygun.min.js", "rg4js"); rg4js('apiKey', 'XXXX OUR API KEY'); rg4js('enableCrashReporting', true); rg4js('options', {allowInsecureSubmissions: true}); } });
In javascripts we have
$(document).ready(function() { try { do some stuff that might fail } catch (ex) { Raygun.send(ex); <-- Here we have the issue we get console error Raygun is not defined }
Any clues what we might have missed .. if we were to remove the try catch the eror would be sent ok but we would like to catch and handle more specific cases than a general failiure.
Any help would be appreciated
Alex
Posted on
Mar 07 2016
Hi Anders,
As both blocks of code are within $(document).ready... blocks they will both be executed at similar times. This means the second block of code which utilizes the Raygun client to send an exception will likely run before the Raygun library has finished loading asynchronously which is triggered in the first block of code.
If you include the first block of code within the head of your page and remove the "$(document).ready..." surrounding it then the Raygun library will start downloading straight away and the library will be initialized prior to your second code block which executes once the document is ready.
Hope that makes sense, let us know how you get on.
Best regards,
Alex
Anders
Posted on
Mar 07 2016
Totally makes sense , Thanks for your support Alex