Skip to content

Commit 16de35e

Browse files
keithamuskoddsson
andauthored
move UA parsing detection to separate script at bottom of the page
- moving to the bottom skips racey DOMReady - moving into a separate script tag means this still runs when module import fails Co-authored-by: Kristján Oddsson <[email protected]>
1 parent 410f9af commit 16de35e

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

docs/index.html

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,6 @@
4949
<script type="module" defer>
5050
import {isSupported, isPolyfilled, baseSupport, apply, polyfills} from '../lib/index.js'
5151
// import {isSupported, isPolyfilled, apply, poyfills} from 'https://unpkg.com/@github/browser-support@latest/lib/index.js'
52-
function getBrowser(useragent) {
53-
if ('userAgentData' in navigator) {
54-
const {brand, version} = Array.from(navigator.userAgentData.brands).pop()
55-
return [brand, version]
56-
}
57-
const parts = useragent.split(' ')
58-
let [name, version] = parts.pop().split('/')
59-
if (name === 'Safari') {
60-
version = parts.pop().split('/').pop()
61-
}
62-
return [name, version]
63-
}
64-
const [browser, version] = getBrowser(navigator.userAgent)
65-
document.getElementById('your-browser').innerText = browser + " " + version
6652
for(const el of document.querySelectorAll('[data-code]')) {
6753
let supported = false
6854
const code = el.getAttribute('data-code')
@@ -664,5 +650,21 @@
664650
** This feature is used, but we Transpile it to a compatible syntax.
665651
</small>
666652
</p>
653+
<script>
654+
function getBrowser(useragent) {
655+
if ('userAgentData' in navigator) {
656+
const {brand, version} = Array.from(navigator.userAgentData.brands).pop()
657+
return [brand, version]
658+
}
659+
const parts = useragent.split(' ')
660+
let [name, version] = parts.pop().split('/')
661+
if (name === 'Safari') {
662+
version = parts.pop().split('/').pop()
663+
}
664+
return [name, version]
665+
}
666+
const [browser, version] = getBrowser(navigator.userAgent)
667+
document.getElementById('your-browser').innerText = browser + " " + version
668+
</script>
667669
</body>
668670
</html>

0 commit comments

Comments
 (0)