-
Notifications
You must be signed in to change notification settings - Fork 316
/
runtime-checks.js
36 lines (32 loc) · 1.16 KB
/
runtime-checks.js
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
'use strict'
/* eslint-env browser, webextensions */
function getBrowserInfo (browser) {
if (browser && browser.runtime && browser.runtime.getBrowserInfo) {
return browser.runtime.getBrowserInfo()
}
return Promise.resolve()
}
function getPlatformInfo (browser) {
if (browser && browser.runtime && browser.runtime.getPlatformInfo) {
return browser.runtime.getPlatformInfo()
}
return Promise.resolve()
}
async function createRuntimeChecks (browser) {
// browser
const browserInfo = await getBrowserInfo(browser)
const runtimeBrowserName = browserInfo ? browserInfo.name : 'unknown'
const runtimeIsFirefox = !!(runtimeBrowserName.includes('Firefox') || runtimeBrowserName.includes('Fennec'))
const runtimeHasNativeProtocol = !!(browser && browser.protocol && browser.protocol.registerStringProtocol)
// platform
const platformInfo = await getPlatformInfo(browser)
const runtimeIsAndroid = platformInfo ? platformInfo.os === 'android' : false
//
return Object.freeze({
browser,
isFirefox: runtimeIsFirefox,
isAndroid: runtimeIsAndroid,
hasNativeProtocolHandler: runtimeHasNativeProtocol
})
}
module.exports = createRuntimeChecks