2019-04-23 09:16:56 +00:00
|
|
|
export const ModernBrowsers = {
|
|
|
|
Edge: '16',
|
|
|
|
Firefox: '60',
|
|
|
|
Chrome: '61',
|
|
|
|
'Chrome Headless': '61',
|
|
|
|
Chromium: '61',
|
|
|
|
Iron: '61',
|
|
|
|
Safari: '10.1',
|
|
|
|
Opera: '48',
|
|
|
|
Yandex: '18',
|
|
|
|
Vivaldi: '1.14',
|
|
|
|
'Mobile Safari': '10.3'
|
|
|
|
}
|
2018-12-22 21:05:13 +00:00
|
|
|
|
2020-02-09 11:17:39 +00:00
|
|
|
const modernBrowsers = new Proxy(ModernBrowsers, {
|
|
|
|
get (browsers, prop) {
|
|
|
|
if (browsers[prop] && !browsers[prop].version) {
|
|
|
|
const coerce = require('semver/functions/coerce')
|
|
|
|
browsers[prop] = coerce(browsers[prop])
|
|
|
|
}
|
|
|
|
return browsers[prop]
|
|
|
|
}
|
|
|
|
})
|
2018-11-07 23:37:06 +00:00
|
|
|
|
2019-04-23 09:16:56 +00:00
|
|
|
export const isModernBrowser = (ua) => {
|
2018-12-10 21:35:04 +00:00
|
|
|
if (!ua) {
|
|
|
|
return false
|
|
|
|
}
|
2020-02-09 11:17:39 +00:00
|
|
|
const coerce = require('semver/functions/coerce')
|
|
|
|
const gte = require('semver/functions/gte')
|
|
|
|
const UAParser = require('ua-parser-js')
|
2018-12-10 21:35:04 +00:00
|
|
|
const { browser } = UAParser(ua)
|
2020-02-09 11:17:39 +00:00
|
|
|
const browserVersion = coerce(browser.version)
|
2019-01-02 21:52:09 +00:00
|
|
|
if (!browserVersion) {
|
|
|
|
return false
|
|
|
|
}
|
2020-02-09 11:17:39 +00:00
|
|
|
return Boolean(modernBrowsers[browser.name] && gte(browserVersion, modernBrowsers[browser.name]))
|
2018-11-07 23:37:06 +00:00
|
|
|
}
|
|
|
|
|
2019-04-23 09:16:56 +00:00
|
|
|
export const isModernRequest = (req, modernMode = false) => {
|
|
|
|
if (modernMode === false) {
|
|
|
|
return false
|
2018-12-24 16:26:39 +00:00
|
|
|
}
|
2019-02-08 16:25:11 +00:00
|
|
|
|
2019-04-23 09:16:56 +00:00
|
|
|
const { socket = {}, headers } = req
|
|
|
|
if (socket._modern === undefined) {
|
|
|
|
const ua = headers && headers['user-agent']
|
|
|
|
socket._modern = isModernBrowser(ua)
|
2019-02-14 13:21:11 +00:00
|
|
|
}
|
2019-04-23 09:16:56 +00:00
|
|
|
|
|
|
|
return socket._modern
|
2018-11-07 23:37:06 +00:00
|
|
|
}
|
2019-07-06 15:22:50 +00:00
|
|
|
|
|
|
|
// https://gist.github.com/samthor/64b114e4a4f539915a95b91ffd340acc
|
2019-11-26 22:42:39 +00:00
|
|
|
export const safariNoModuleFix = '!function(){var e=document,t=e.createElement("script");if(!("noModule"in t)&&"onbeforeload"in t){var n=!1;e.addEventListener("beforeload",function(e){if(e.target===t)n=!0;else if(!e.target.hasAttribute("nomodule")||!n)return;e.preventDefault()},!0),t.type="module",t.src=".",e.head.appendChild(t),t.remove()}}();'
|