-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshowBrowserProps.html
More file actions
245 lines (218 loc) · 10.7 KB
/
Copy pathshowBrowserProps.html
File metadata and controls
245 lines (218 loc) · 10.7 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
<title>Show Browser Properties</title>
<style type="text/css">
:root {
--ackTextColor:rgb(33, 37, 41); --ackBgColor:white;
--ackTableBorderColor:darkgray; --ackTableSectBgColor:darkslateblue; --ackTableSectTextColor:white;
--ackTableThBgColor:lavender; --ackTableTdBgColor:white;
--ackButtonBgColor:ButtonFace; --ackButtonTextColor:ButtonText; --ackButtonBorderColor:ButtonBorder;
}
@media (prefers-color-scheme: dark) {
:root {
--ackTextColor:rgb(204,204,204); --ackBgColor:rgb(48, 44, 51);
--ackTableBorderColor:rgb(75, 67, 82); --ackTableSectBgColor:rgb(30, 25, 45); --ackTableSectTextColor:gainsboro;
--ackTableThBgColor:rgb(50, 42, 78); --ackTableTdBgColor:rgb(55, 51, 58);
--ackButtonBgColor:rgb(43, 42, 51); --ackButtonTextColor:var(--ackTextColor); --ackButtonBorderColor:rgb(117, 116, 122);
}
}
body { background-color: var(--ackBgColor); color: var(--ackTextColor); }
div#wrapper { width: 100%; }
@media (min-width:1200px) { div#wrapper { max-width: 75%; margin-inline: auto; } }
table.dataTbl { border-collapse: collapse; width: 100%; margin: 0; }
table.dataTbl td, table.dataTbl th { font-size:14px; font-family:Tahoma,sans-serif; border: 1px solid var(--ackTableBorderColor); padding:6px; /*white-space: nowrap;*/ }
table.dataTbl td { background-color: var(--ackTableTdBgColor); }
/* table.dataTbl thead th { background-color: lightsteelblue; text-align: center; } */
table.dataTbl tbody tr th { background-color: var(--ackTableThBgColor); text-align: right; }
table.dataTbl thead th.section { background-color: var(--ackTableSectBgColor); color: var(--ackTableSectTextColor); text-align: center; }
/* make main table header always visible: */
/* div#wrapper { overflow-x: scroll; overflow-y: scroll; max-height: 97vh; } */
/* table#data thead th { position: sticky; top: 0; z-index: 99; } */
table.dataTbl td ul { margin: 0; padding-left: 1em; }
button { background-color: var(--ackButtonBgColor); color: var(--ackButtonTextColor); border-color: var(--ackButtonBorderColor); }
</style>
</head>
<body>
<div id="wrapper">
<div id="tblWrapper"></div>
<div style="margin-top: 1em;"><button onclick="setBrowserInfo();">Refresh</button></div>
</div>
<script>
document.addEventListener('DOMContentLoaded', setBrowserInfo); // or window.addEventListener('load', ...), not sure which is better or if it matters
window.addEventListener('resize', setBrowserInfo);
async function setBrowserInfo() {
const dataDiv = document.getElementById('tblWrapper');
// remove any existing data:
while (dataDiv.firstChild) { dataDiv.removeChild(dataDiv.firstChild); }
addNavigatorInfo().render(dataDiv);
addVisualViewportInfo().render(dataDiv);
(await addUserAgentData()).render(dataDiv);
addMediaQueryInfo().render(dataDiv);
}
class nameValue {
constructor(n, v) { this.name = n; this.value = v; }
}
class nameValueRow {
constructor() { this.nameValues = []; }
addNameValue(nv) { this.nameValues.push(nv); }
static fromNameValues(nvArray) {
const result = new nameValueRow();
if (nvArray) { for (const nv of nvArray) { result.addNameValue(nv); } }
return result;
}
}
class nameValueSection {
static columnSpreads = {
// main index is max number of nameValues for table; subindex is number in current row; array is colspan for given member
1: { 1: [1], },
2: { 1: [3], 2: [1,1], },
3: { 1: [5], 2: [2,2], 3: [1,1,1], },
4: { 1: [7], 2: [3,3], 3: [2,2,1], 4: [1,1,1,1], },
5: { 1: [9], 2: [4,4], 3: [2,2,2,1], 4: [2,2,1,1], 5: [1,1,1,1,1] },
}
constructor(sectionTitle) { this.sectionTitle = sectionTitle; this.rows = []; }
addRow(nvRow) { this.rows.push(nvRow); }
render(parent) {
let maxNvCount = 0;
for (const r of this.rows) { if (r.nameValues.length > maxNvCount) { maxNvCount = r.nameValues.length; } }
const tbl = make('table', parent);
tbl.classList.add('dataTbl');
const colgrp = make('colgroup', tbl);
const percentPerNv = 1.0 / maxNvCount; const percentPerName = percentPerNv * 40; const percentPerValue = percentPerNv * 60;
for (let i = 0; i < maxNvCount; ++i) {
make('col', colgrp).style.setProperty("width", `${percentPerName}%`);;
make('col', colgrp).style.setProperty("width", `${percentPerValue}%`);;
}
const thead = make('thead', tbl);
const tbody = make('tbody', tbl);
makeSectionHeader(thead, this.sectionTitle, maxNvCount * 2);
const colSpread = nameValueSection.columnSpreads[maxNvCount];
for (const row of this.rows) {
let valColSpan = colSpread[row.nameValues.length];
const tr = make('tr', tbody);
for (const nv of row.nameValues) {
makeNameValueCells(tr, nv.name, nv.value, valColSpan);
}
}
}
}
function addNavigatorInfo() {
let sect = new nameValueSection('Browser');
sect.addRow(nameValueRow.fromNameValues([ new nameValue('UserAgent', navigator.userAgent) ]));
sect.addRow(nameValueRow.fromNameValues([ new nameValue('Location', window.location.href) ]));
sect.addRow(nameValueRow.fromNameValues([ new nameValue('Languages', navigator.languages) ]));
sect.addRow(nameValueRow.fromNameValues([ new nameValue('ProcCores', navigator.hardwareConcurrency) ]));
// not sure what this one is actualy showing:
//sect.addRow(nameValueRow.fromNameValues([ new nameValue('Memory', navigator.deviceMemory) ]));
// this one's not really supported:
//sect.addRow(nameValueRow.fromNameValues([ new nameValue('NetworkType', navigator.connection.type), new nameValue('Speed', navigator.connection.downlinkMax) ]));
sect.addRow(nameValueRow.fromNameValues([ new nameValue('Online', navigator.onLine) ]));
return sect;
}
function addVisualViewportInfo() {
let viewport = window.visualViewport;
let sect = new nameValueSection('Display');
sect.addRow(nameValueRow.fromNameValues([ new nameValue('ScreenWidth', window.screen.width), new nameValue('ScreenHeight', window.screen.height) ]));
sect.addRow(nameValueRow.fromNameValues([ new nameValue('AvailWidth', window.screen.availWidth), new nameValue('AvailHeight', window.screen.availHeight) ]));
sect.addRow(nameValueRow.fromNameValues([ new nameValue('PixelRatio', round(window.devicePixelRatio, 3)), new nameValue('Orientation', window.screen.orientation.type) ]));
sect.addRow(nameValueRow.fromNameValues([ new nameValue('ColorDepth', window.screen.colorDepth), new nameValue('PixelDepth', window.screen.pixelDepth) ]));
sect.addRow(nameValueRow.fromNameValues([ new nameValue('OuterWidth', window.outerWidth), new nameValue('OuterHeight', window.outerHeight) ]));
sect.addRow(nameValueRow.fromNameValues([ new nameValue('InnerWidth', window.innerWidth), new nameValue('InnerHeight', window.innerHeight) ]));
sect.addRow(nameValueRow.fromNameValues([ new nameValue('ViewportWidth', round(viewport.width, 2)), new nameValue('ViewportHeight', round(viewport.height, 2)) ]));
sect.addRow(nameValueRow.fromNameValues([ new nameValue('ViewportScale', round(viewport.scale, 2)), new nameValue('', '') ]));
return sect;
}
async function addUserAgentData() {
let sect = new nameValueSection('UserAgentData [experimental]');
if (!navigator.userAgentData) {
sect.addRow(nameValueRow.fromNameValues([ new nameValue('UserAgentData', 'N/A') ]));
return sect;
}
let data = navigator.userAgentData;
let ul = make('ul', null);
data.brands.forEach(b => { let li = make('li', ul); makeText(li, (b.brand + ';v=' + b.version)); });
sect.addRow(nameValueRow.fromNameValues([ new nameValue('Brands', ul) ]));
sect.addRow(nameValueRow.fromNameValues([ new nameValue('Platform', data.platform), new nameValue('Mobile', data.mobile) ]));
const values = await data.getHighEntropyValues(['architecture', 'bitness', 'model', 'platformVersion', 'fullVersionList', 'uaFullVersion']);
sect.addRow(nameValueRow.fromNameValues([ new nameValue('PlatformVersion', values.platformVersion), new nameValue('Model', values.model) ]));
sect.addRow(nameValueRow.fromNameValues([ new nameValue('Architecture', values.architecture), new nameValue('Bitness', values.bitness) ]));
ul = make('ul', null);
values.fullVersionList.forEach(b => { let li = make('li', ul); makeText(li, (b.brand + ';v=' + b.version)); });
sect.addRow(nameValueRow.fromNameValues([ new nameValue('FullVersionList', ul) ]));
sect.addRow(nameValueRow.fromNameValues([ new nameValue('UAFullVersion [deprecated]', values.uaFullVersion), new nameValue('', '') ]));
return sect;
}
function addMediaQueryInfo() {
let sect = new nameValueSection('Media Queries');
const prefersColrScheme = checkMediaQuery('prefers-color-scheme', ['light', 'dark']);
const orientation = checkMediaQuery('orientation', ['portrait', 'landscape']);
const displayMode = checkMediaQuery('display-mode', ['fullscreen', 'minimal-ui', 'picture-in-picture', 'standalone', 'window-controls-overlay', 'browser']);
const invertedColors = checkMediaQuery('inverted-colors', ['inverted', 'none']);
sect.addRow(nameValueRow.fromNameValues([
new nameValue('prefers-color-scheme', prefersColrScheme),
new nameValue('orientation', orientation),
]));
sect.addRow(nameValueRow.fromNameValues([
new nameValue('display-mode', displayMode),
new nameValue('inverted-colors', invertedColors),
]));
// TODO:
// width, min-width, height, min-height
// resolution (dpi)
// pointer, hover, any-pointer(?), any-hover(?)
return sect;
function checkMediaQuery(name, possibleValues) {
if (window.matchMedia(`(${name})`).matches) {
for (v of possibleValues) {
if (window.matchMedia(`(${name}: ${v})`).matches) {
return v;
}
}
return '[unknown value]';
} else {
return 'N/A';
}
}
}
function make(name, parent) {
let e = document.createElement(name);
if (parent) { parent.append(e); }
return e;
}
function makeText(parent, value) {
let t = document.createTextNode(value);
parent.append(t);
}
function makeSectionHeader(tbody, name, desiredColumnCnt) {
let row = make('tr', tbody);
let th = make('th', row);
th.colSpan = desiredColumnCnt;
th.classList.add('section');
makeText(th, name);
}
function makeNameValueCells(trow, name, value, valueColSpan) {
th = make('th', trow);
makeText(th, name);
let td = make('td', trow);
if (valueColSpan && valueColSpan > 1)
td.colSpan = valueColSpan;
if (typeof(value) == "string") {
makeText(td, value);
} else if (value instanceof HTMLElement) {
td.append(value);
} else {
makeText(td, value.toString());
}
}
function round(value, maxDecimalPlaces) {
if (maxDecimalPlaces <= 0)
return Math.round(value);
let mult = Math.pow(10, maxDecimalPlaces) * 1.0;
return (Math.round(value * mult) / mult);
}
</script>
</body>
</html>