Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 7b1d045

Browse files
Hamish-taylortaylorhami
authored and
taylorhami
committed
Added global var to check rg initilisation
1 parent e9ea6ce commit 7b1d045

File tree

2 files changed

+38
-30
lines changed

2 files changed

+38
-30
lines changed

src/raygun.loader.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@
222222
window[window['RaygunObject']] = function() {
223223
return executor(arguments);
224224
};
225-
225+
window['RaygunInitialized'] = true;
226226
globalExecutorInstalled = true;
227227
};
228228

src/umd.intro.js

+37-29
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// https://github.com/umdjs/umd/blob/master/templates/returnExportsGlobal.js
22

3-
(function (root, factory) {
3+
(function(root, factory) {
44
if (typeof define === 'function' && define.amd) {
55
// AMD. Register as an anonymous module.
6-
define('raygun4js', function () {
6+
define('raygun4js', function() {
77
return (root.Raygun = factory());
88
});
99
} else if (typeof module === 'object' && module.exports) {
@@ -15,34 +15,42 @@
1515
// Browser globals
1616
root.Raygun = factory();
1717
}
18-
}(this, function () {
18+
}(this, function() {
1919

20-
var windw = this || window || global;
21-
var originalOnError = windw.onerror;
22-
windw.onerror = function (msg, url, line, col, err) {
23-
if (originalOnError) {
24-
originalOnError(msg, url, line, col, err);
25-
}
20+
var windw = this || window || global;
21+
var originalOnError = windw.onerror;
22+
windw.onerror = function(msg, url, line, col, err) {
23+
if (originalOnError) {
24+
originalOnError(msg, url, line, col, err);
25+
}
2626

27-
if (!err) {
28-
err = new Error(msg);
29-
}
27+
if (!err) {
28+
err = new Error(msg);
29+
}
30+
31+
windw['rg4js'].q = windw['rg4js'].q || [];
32+
windw['rg4js'].q.push({ e: err });
33+
};
34+
let isWindowLoaded = false;
3035

31-
windw['rg4js'].q = windw['rg4js'].q || [];
32-
windw['rg4js'].q.push({e: err});
33-
};
36+
window.onload = function() {
37+
isWindowLoaded = true;
38+
};
39+
// Similar approach as the snippet, creates the rg4js proxy function, which is exported in umd.outro.js once the
40+
// script is executed, and later overwritten by the loader once it's finished
41+
(function(wind) {
42+
wind['RaygunObject'] = 'rg4js';
43+
wind[wind['RaygunObject']] = wind[wind['RaygunObject']] || function() {
44+
if (wind && typeof wind['Raygun'] === 'undefined' ||
45+
(typeof document === 'undefined' || document.readyState !== 'complete') || (wind['RaygunInitialized'] || false) === false) {
46+
// onload hasn't been called, cache the commands just like the snippet
47+
(wind[wind['RaygunObject']].o = wind[wind['RaygunObject']].o || []).push(arguments)
48+
} else {
49+
// onload has been called and provider has executed, call the executor proxy function
50+
var test = wind[wind['RaygunObject']];
51+
console.log(test);
52+
return wind[wind['RaygunObject']](arguments[0], arguments[1]);
53+
}
3454

35-
// Similar approach as the snippet, creates the rg4js proxy function, which is exported in umd.outro.js once the
36-
// script is executed, and later overwritten by the loader once it's finished
37-
(function(wind) { wind['RaygunObject'] = 'rg4js';
38-
wind[wind['RaygunObject']] = wind[wind['RaygunObject']] || function() {
39-
if (wind && typeof wind['Raygun'] === 'undefined' ||
40-
(typeof document === 'undefined' || document.readyState !== 'complete')) {
41-
// onload hasn't been called, cache the commands just like the snippet
42-
(wind[wind['RaygunObject']].o = wind[wind['RaygunObject']].o || []).push(arguments)
43-
} else {
44-
// onload has been called and provider has executed, call the executor proxy function
45-
return wind[wind['RaygunObject']](arguments[0], arguments[1]);
46-
}
47-
48-
}})(windw);
55+
}
56+
})(windw);

0 commit comments

Comments
 (0)