-
Notifications
You must be signed in to change notification settings - Fork 286
/
in-page-script.js
52 lines (49 loc) · 1.51 KB
/
in-page-script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* The Chrome and Firefox extensions inject the in-page-script into the
* page to determine the version of Ember the ClientApp is running.
*
* An iife runs to gather the data and uses postMessage to send the data back
* to the extension.
*
* @namespace EmberInspector/Shared
* @class InPageScript
*/
(function() {
"use strict";
function onReady(callback) {
if (document.readyState === 'complete' || document.readyState === 'interactive') {
setTimeout(completed);
} else {
document.addEventListener("DOMContentLoaded", completed, false);
// For some reason DOMContentLoaded doesn't always work
window.addEventListener("load", completed, false);
}
function completed() {
document.removeEventListener("DOMContentLoaded", completed, false);
window.removeEventListener("load", completed, false);
callback();
}
}
onReady(function() {
let Ember;
try {
Ember = requireModule('ember')['default'];
} catch {
Ember = window.Ember;
}
var libraries = Ember && Ember.libraries;
if (libraries) {
// Ember has changed where the array of libraries is located.
// In older versions, `Ember.libraries` was the array itself,
// but now it's found under _registry.
if (libraries._registry) {
libraries = libraries._registry;
}
var versions = Array.prototype.slice.call(libraries, 0);
window.postMessage({
type: 'emberVersion',
versions: versions
}, '*');
}
});
}());