-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
chrome-versions.cjs
106 lines (94 loc) · 4.61 KB
/
chrome-versions.cjs
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* USED FOR SITESPEED TEST (TO collect software and javascript used)!!!
*/
module.exports = async function (context, commands) {
// cdpClient = commands.cdp.engineDelegate.getCDPClient()
// https://chromedevtools.github.io/devtools-protocol/tot/Storage/#method-getCookies
// bodyResult = await cdpClient.send('Runtime.evaluate', {
// 'expression': 'document.location.href'
// });
// await commands.wait.byTime(20000);
// bodyResult = await cdpClient.send('Runtime.evaluate', {
// 'allowUnsafeEvalBlockedByCSP': true,
// 'expression': '"jQuery" in window && "fn" in window.jQuery && "jquery" in window.jQuery.fn ? window.jQuery.fn.jquery : ""'
// });
// commands.wait.byCondition(commands.wait.byPageToComplete, 5000);
try {
// Fix for exception thrown on some pages where this function doesn't trigger until timeout: https://github.com/sitespeedio/browsertime/blob/main/lib/core/engine/command/wait.js#L126
await commands.wait.byPageToComplete();
} catch (error) {
}
core_js_versions = [];
try {
core_js_count = await commands.js.run('return "__core-js_shared__" in window && "versions" in window["__core-js_shared__"] ? window["__core-js_shared__"]["versions"].length : 0')
for (let index = 0; index < core_js_count; index++) {
value = await commands.js.run('return "__core-js_shared__" in window && "versions" in window["__core-js_shared__"] ? window["__core-js_shared__"]["versions"][' + index +']["version"] : -1')
if (value.indexOf('ERROR') === -1) {
core_js_versions.push(value);
}
}
} catch (error) {
console.error(error);
}
modernizr_versions = []
try {
modernizr_versions = await commands.js.run('return "Modernizr" in window && "_version" in window.Modernizr ? [window.Modernizr._version] : []');
} catch (error) {
console.error(error);
}
alpine_versions = []
try {
alpine_versions = await commands.js.run('return "Alpine" in window && "version" in window.Alpine ? [window.Alpine.version] : []');
} catch (error) {
console.error(error);
}
next_versions = []
try {
next_versions = await commands.js.run('return "next" in window && "version" in window.next ? [window.next.version] : []');
} catch (error) {
console.error(error);
}
jquery_versions = []
try {
tmp = await commands.js.run('return typeof jQuery !== "undefined"');
tmp = await commands.js.run('return typeof jQuery !== "undefined" && typeof jQuery.prototype !== "undefined"');
tmp = await commands.js.run('return typeof jQuery !== "undefined" && typeof jQuery.prototype !== "undefined" && jQuery.prototype.jquery !== "undefined"');
jquery_versions = await commands.js.run('return typeof jQuery !== "undefined" && typeof jQuery.prototype !== "undefined" && jQuery.prototype.jquery !== "undefined" ? [jQuery.prototype.jquery] : []');
// Add support for "jQuery running noConflict"
tmp = await commands.js.run('return "jQuery" in window');
if (tmp) {
jquery_versions = await commands.js.run(
[
"jquery_versions = []",
"for (x in window) {",
"if ((typeof(window[x]) === 'object' || typeof(window[x]) === 'function') && typeof (window[x]) !== 'undefined' && window[x] !== null) {",
"if (Object.keys(window[x]).indexOf('fn') !== -1) {",
"if (window[x] && 'jquery' in window[x]['fn']) {",
"jquery_versions.push(window[x]['fn']['jquery'])",
"}",
"}",
"}",
"}",
"return jquery_versions;"
].join('\r\n'));
}
if (jquery_versions === null || jquery_versions == {}) {
jquery_versions = []
}
} catch (error) {
console.error(error);
}
versions = {
'jquery': jquery_versions,
'modernizr': modernizr_versions,
'core-js': core_js_versions,
'next.js': next_versions,
'alpinejs': alpine_versions
}
// window['__core-js_shared__'].versions
// bodyResult = await commands.js.run('return { "jquery": "jQuery" in window && "fn" in window.jQuery && "jquery" in window.jQuery.fn ? window.jQuery.fn.jquery : ""}');
// bodyResult = await cdpClient.send('Runtime.evaluate', {
// 'expression': 'window.jQuery.fn.jquery'
// });
context.log.info('VERSIONS:START:', versions, 'VERSIONS:END');
}