forked from dequelabs/axe-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-environment-data.js
More file actions
43 lines (40 loc) · 1.05 KB
/
get-environment-data.js
File metadata and controls
43 lines (40 loc) · 1.05 KB
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
/**
* Add information about the environment axe was run in.
* @return {EnvironmentData}
*/
export default function getEnvironmentData(metadata = null, win = window) {
if (metadata && typeof metadata === 'object') {
return metadata;
} else if (typeof win !== 'object') {
return {};
}
return {
testEngine: {
name: 'axe-core',
version: axe.version
},
testRunner: {
name: axe._audit.brand
},
testEnvironment: getTestEnvironment(win),
timestamp: new Date().toISOString(),
url: win.location?.href
};
}
function getTestEnvironment(win) {
if (!win.navigator || typeof win.navigator !== 'object') {
return {};
}
const { navigator, innerHeight, innerWidth } = win;
const { angle, type } = getOrientation(win) || {};
return {
userAgent: navigator.userAgent,
windowWidth: innerWidth,
windowHeight: innerHeight,
orientationAngle: angle,
orientationType: type
};
}
function getOrientation({ screen }) {
return screen.orientation || screen.msOrientation || screen.mozOrientation;
}