Raygun 2.4.1 blocking main thread

k.art

Posted on
Nov 09 2016

We are using raygun inside a chrome extension. It gets injected into a webpage. The script looks as follows:

let RAYGUN_SRC = "//cdn.raygun.io/raygun4js/raygun.min.js"
!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",RAYGUN_SRC,"rg4js");

rg4js('apiKey', '<our api key>');
rg4js('enableCrashReporting', true);

On execution the following error is printed in the console: Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.

It happens on line :344 in raygun.js

1 /*! Raygun4js - v2.4.1 - 2016-09-07
2 * https://github.com/MindscapeHQ/raygun4js
3 * Copyright (c) 2016 MindscapeHQ; Licensed MIT */

344 request.open('GET', url, false);

Questions:

  1. Shouldn't the request be executed asynchronously? E.g. request.open('GET', url, true);
  2. Is it possible to download the latest script (raygun.min.js) and make it available as rg4js?

k.art

Posted on
Nov 09 2016

Question 3: Maybe what I am trying to achieve is not possible and I have to fallback to v1 instead of using rg4js?


k.art

Posted on
Nov 09 2016

I've got it working by injecting raygun.min.js directly and using v1.


Callum

Posted on
Nov 10 2016

Great to hear you got it working - you have indeed found the most appropriate approach for getting Raygun4JS working in your scenario. For those cases where the script can be bundled with an app, the V1 API is intended to be used as the script is available immediately without needing to incur a network request and download. The V2 API exists to support this asynchronous scenario which is the common case for the majority of web pages and applications, but other, more app-like scenarios such as Chrome extensions have the resources bundled and thus can use synchronous loading and call into the library immediately.

I've made a note to clarify this in the documentation for future users. We hope Raygun proves to be useful for your Chrome extension.


Reply