@subwallet/extension-base 1.1.35-beta.1 → 1.1.35-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/utils/environment.js +16 -14
- package/cjs/utils/mv3.js +1 -1
- package/package.json +1 -1
- package/utils/environment.js +16 -11
- package/utils/mv3.js +1 -1
package/cjs/utils/environment.js
CHANGED
|
@@ -8,24 +8,24 @@ exports.targetIsWeb = exports.targetIsMobile = exports.targetIsExtension = expor
|
|
|
8
8
|
var _mv = require("@subwallet/extension-base/utils/mv3");
|
|
9
9
|
var _bowser = _interopRequireDefault(require("bowser"));
|
|
10
10
|
var _KoniTypes = require("../background/KoniTypes");
|
|
11
|
-
|
|
12
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
13
|
-
|
|
11
|
+
var _navigator3;
|
|
14
12
|
function detectRuntimeEnvironment() {
|
|
15
|
-
if (_mv.isSupportWindow) {
|
|
13
|
+
if (_mv.isSupportWindow && typeof document !== 'undefined') {
|
|
14
|
+
var _navigator, _window$location, _window$location2;
|
|
16
15
|
// Web environment
|
|
17
16
|
return {
|
|
18
17
|
environment: _KoniTypes.RuntimeEnvironment.Web,
|
|
19
|
-
version: navigator.userAgent,
|
|
20
|
-
host: window.location.host,
|
|
21
|
-
protocol: window.location.protocol
|
|
18
|
+
version: (_navigator = navigator) === null || _navigator === void 0 ? void 0 : _navigator.userAgent,
|
|
19
|
+
host: (_window$location = window.location) === null || _window$location === void 0 ? void 0 : _window$location.host,
|
|
20
|
+
protocol: (_window$location2 = window.location) === null || _window$location2 === void 0 ? void 0 : _window$location2.protocol
|
|
22
21
|
};
|
|
23
22
|
} else if (typeof self !== 'undefined' && typeof importScripts !== 'undefined') {
|
|
23
|
+
var _navigator2, _self$location;
|
|
24
24
|
// Service Worker environment
|
|
25
25
|
return {
|
|
26
26
|
environment: _KoniTypes.RuntimeEnvironment.ServiceWorker,
|
|
27
|
-
version: navigator.userAgent,
|
|
28
|
-
host: self.location.host,
|
|
27
|
+
version: (_navigator2 = navigator) === null || _navigator2 === void 0 ? void 0 : _navigator2.userAgent,
|
|
28
|
+
host: (_self$location = self.location) === null || _self$location === void 0 ? void 0 : _self$location.host,
|
|
29
29
|
protocol: 'https'
|
|
30
30
|
};
|
|
31
31
|
} else if (typeof process !== 'undefined' && process.versions && process.versions.node) {
|
|
@@ -35,20 +35,22 @@ function detectRuntimeEnvironment() {
|
|
|
35
35
|
version: process.versions.node
|
|
36
36
|
};
|
|
37
37
|
} else if (typeof chrome !== 'undefined' && typeof chrome.runtime !== 'undefined') {
|
|
38
|
+
var _window$location3, _window$location4;
|
|
38
39
|
// Extension environment (Chrome)
|
|
39
40
|
return {
|
|
40
41
|
environment: _KoniTypes.RuntimeEnvironment.ExtensionChrome,
|
|
41
42
|
version: chrome.runtime.getManifest().version,
|
|
42
|
-
host: window.location.host,
|
|
43
|
-
protocol: window.location.protocol
|
|
43
|
+
host: (_window$location3 = window.location) === null || _window$location3 === void 0 ? void 0 : _window$location3.host,
|
|
44
|
+
protocol: (_window$location4 = window.location) === null || _window$location4 === void 0 ? void 0 : _window$location4.protocol
|
|
44
45
|
};
|
|
45
46
|
} else if (typeof browser !== 'undefined' && typeof browser.runtime !== 'undefined') {
|
|
47
|
+
var _window$location5, _window$location6;
|
|
46
48
|
// Extension environment (Firefox)
|
|
47
49
|
return {
|
|
48
50
|
environment: _KoniTypes.RuntimeEnvironment.ExtensionFirefox,
|
|
49
51
|
version: browser.runtime.getManifest().version,
|
|
50
|
-
host: window.location.host,
|
|
51
|
-
protocol: window.location.protocol
|
|
52
|
+
host: (_window$location5 = window.location) === null || _window$location5 === void 0 ? void 0 : _window$location5.host,
|
|
53
|
+
protocol: (_window$location6 = window.location) === null || _window$location6 === void 0 ? void 0 : _window$location6.protocol
|
|
52
54
|
};
|
|
53
55
|
// @ts-ignore
|
|
54
56
|
} else if (typeof WorkerGlobalScope !== 'undefined') {
|
|
@@ -69,7 +71,7 @@ const RuntimeInfo = detectRuntimeEnvironment();
|
|
|
69
71
|
|
|
70
72
|
// Todo: Support more in backend case
|
|
71
73
|
exports.RuntimeInfo = RuntimeInfo;
|
|
72
|
-
const BowserParser = _bowser.default.getParser(typeof navigator !== 'undefined' ? navigator.userAgent : '');
|
|
74
|
+
const BowserParser = _bowser.default.getParser(typeof navigator !== 'undefined' ? ((_navigator3 = navigator) === null || _navigator3 === void 0 ? void 0 : _navigator3.userAgent) + '' : '');
|
|
73
75
|
exports.BowserParser = BowserParser;
|
|
74
76
|
const isFirefox = BowserParser.getBrowserName(true) === 'firefox';
|
|
75
77
|
exports.isFirefox = isFirefox;
|
package/cjs/utils/mv3.js
CHANGED
|
@@ -17,5 +17,5 @@ function detectMv3() {
|
|
|
17
17
|
}
|
|
18
18
|
const isManifestV3 = detectMv3();
|
|
19
19
|
exports.isManifestV3 = isManifestV3;
|
|
20
|
-
const isSupportWindow = typeof window !== 'undefined';
|
|
20
|
+
const isSupportWindow = typeof window !== 'undefined' && !!window;
|
|
21
21
|
exports.isSupportWindow = isSupportWindow;
|
package/package.json
CHANGED
package/utils/environment.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
var _navigator3;
|
|
1
2
|
// Copyright 2019-2022 @polkadot/extension authors & contributors
|
|
2
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
4
|
|
|
@@ -5,20 +6,22 @@ import { isSupportWindow } from '@subwallet/extension-base/utils/mv3';
|
|
|
5
6
|
import Bowser from 'bowser';
|
|
6
7
|
import { RuntimeEnvironment } from "../background/KoniTypes.js";
|
|
7
8
|
function detectRuntimeEnvironment() {
|
|
8
|
-
if (isSupportWindow) {
|
|
9
|
+
if (isSupportWindow && typeof document !== 'undefined') {
|
|
10
|
+
var _navigator, _window$location, _window$location2;
|
|
9
11
|
// Web environment
|
|
10
12
|
return {
|
|
11
13
|
environment: RuntimeEnvironment.Web,
|
|
12
|
-
version: navigator.userAgent,
|
|
13
|
-
host: window.location.host,
|
|
14
|
-
protocol: window.location.protocol
|
|
14
|
+
version: (_navigator = navigator) === null || _navigator === void 0 ? void 0 : _navigator.userAgent,
|
|
15
|
+
host: (_window$location = window.location) === null || _window$location === void 0 ? void 0 : _window$location.host,
|
|
16
|
+
protocol: (_window$location2 = window.location) === null || _window$location2 === void 0 ? void 0 : _window$location2.protocol
|
|
15
17
|
};
|
|
16
18
|
} else if (typeof self !== 'undefined' && typeof importScripts !== 'undefined') {
|
|
19
|
+
var _navigator2, _self$location;
|
|
17
20
|
// Service Worker environment
|
|
18
21
|
return {
|
|
19
22
|
environment: RuntimeEnvironment.ServiceWorker,
|
|
20
|
-
version: navigator.userAgent,
|
|
21
|
-
host: self.location.host,
|
|
23
|
+
version: (_navigator2 = navigator) === null || _navigator2 === void 0 ? void 0 : _navigator2.userAgent,
|
|
24
|
+
host: (_self$location = self.location) === null || _self$location === void 0 ? void 0 : _self$location.host,
|
|
22
25
|
protocol: 'https'
|
|
23
26
|
};
|
|
24
27
|
} else if (typeof process !== 'undefined' && process.versions && process.versions.node) {
|
|
@@ -28,20 +31,22 @@ function detectRuntimeEnvironment() {
|
|
|
28
31
|
version: process.versions.node
|
|
29
32
|
};
|
|
30
33
|
} else if (typeof chrome !== 'undefined' && typeof chrome.runtime !== 'undefined') {
|
|
34
|
+
var _window$location3, _window$location4;
|
|
31
35
|
// Extension environment (Chrome)
|
|
32
36
|
return {
|
|
33
37
|
environment: RuntimeEnvironment.ExtensionChrome,
|
|
34
38
|
version: chrome.runtime.getManifest().version,
|
|
35
|
-
host: window.location.host,
|
|
36
|
-
protocol: window.location.protocol
|
|
39
|
+
host: (_window$location3 = window.location) === null || _window$location3 === void 0 ? void 0 : _window$location3.host,
|
|
40
|
+
protocol: (_window$location4 = window.location) === null || _window$location4 === void 0 ? void 0 : _window$location4.protocol
|
|
37
41
|
};
|
|
38
42
|
} else if (typeof browser !== 'undefined' && typeof browser.runtime !== 'undefined') {
|
|
43
|
+
var _window$location5, _window$location6;
|
|
39
44
|
// Extension environment (Firefox)
|
|
40
45
|
return {
|
|
41
46
|
environment: RuntimeEnvironment.ExtensionFirefox,
|
|
42
47
|
version: browser.runtime.getManifest().version,
|
|
43
|
-
host: window.location.host,
|
|
44
|
-
protocol: window.location.protocol
|
|
48
|
+
host: (_window$location5 = window.location) === null || _window$location5 === void 0 ? void 0 : _window$location5.host,
|
|
49
|
+
protocol: (_window$location6 = window.location) === null || _window$location6 === void 0 ? void 0 : _window$location6.protocol
|
|
45
50
|
};
|
|
46
51
|
// @ts-ignore
|
|
47
52
|
} else if (typeof WorkerGlobalScope !== 'undefined') {
|
|
@@ -61,7 +66,7 @@ function detectRuntimeEnvironment() {
|
|
|
61
66
|
export const RuntimeInfo = detectRuntimeEnvironment();
|
|
62
67
|
|
|
63
68
|
// Todo: Support more in backend case
|
|
64
|
-
export const BowserParser = Bowser.getParser(typeof navigator !== 'undefined' ? navigator.userAgent : '');
|
|
69
|
+
export const BowserParser = Bowser.getParser(typeof navigator !== 'undefined' ? ((_navigator3 = navigator) === null || _navigator3 === void 0 ? void 0 : _navigator3.userAgent) + '' : '');
|
|
65
70
|
export const isFirefox = BowserParser.getBrowserName(true) === 'firefox';
|
|
66
71
|
export const osName = BowserParser.getOSName();
|
|
67
72
|
export const isMobile = BowserParser.getPlatform().type === 'mobile';
|
package/utils/mv3.js
CHANGED