forked from GoogleChromeLabs/uach-retrofill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.html
69 lines (62 loc) · 2.25 KB
/
demo.html
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
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
<style>
body {
font-family: sans-serif;
}
h1, h2 {
font-size: 1rem;
}
label {
display: block;
}
.override-ua {
background: lightgoldenrodyellow;
}
</style>
<title>UA-CH Retrofill</title>
<h1>UA-CH Retrofill</h1>
<p><code>import { overrideUserAgentUsingClientHints } from './uach-retrofill.js';</code></p>
<p><code>overrideUserAgentUsingClientHints([</code></p>
<form>
<label><input type="checkbox" name="architecture"><code>'architecture'</code></label>
<label><input type="checkbox" name="bitness"><code>'bitness'</code></label>
<label><input type="checkbox" name="model"><code>'model'</code></label>
<label><input type="checkbox" name="platformVersion"><code>'platformVersion'</code></label>
<label><input type="checkbox" name="uaFullVersion"><code>'uaFullVersion'</code></label>
<label><input type="checkbox" name="wow64"><code>'wow64'</code></label>
</form>
<p><code>then(() => {
document.querySelector('.override-ua').textContent = navigator.userAgent;
});
</code></p>
<h2>Initial User-Agent</h2>
<p><code>navigator.userAgent == <span class="initial-ua"></span></code></p>
<h2>Generated User-Agent</h2>
<p><code>navigator.userAgent == <span class="override-ua"></span></code></p>
<script type="module">
'use strict';
import { getUserAgentUsingClientHints, overrideUserAgentUsingClientHints } from './uach-retrofill.js';
document.querySelector('.initial-ua').textContent = navigator.userAgent;
// Generate the equivalent string and override navigator.userAgent
overrideUserAgentUsingClientHints([]).then(() => {
document.querySelector('.override-ua').textContent = navigator.userAgent;
});
const hintBoxes = document.querySelectorAll('input[type=checkbox]');
hintBoxes.forEach(el => {
el.addEventListener('change', ev => {
let hints = [];
hintBoxes.forEach(cb => {
if (cb.checked === true) {
hints.push(cb.name);
}
});
overrideUserAgentUsingClientHints(hints).then(() => {
document.querySelector('.override-ua').textContent = navigator.userAgent;
});
});
});
</script>