@onekeyfe/extension-bridge-hosted 0.0.3 → 0.0.4
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.
|
@@ -7,6 +7,7 @@ declare class JsBridgeExtBackground extends JsBridgeBase {
|
|
|
7
7
|
ports: Record<number | string, chrome.runtime.Port>;
|
|
8
8
|
private portIdIndex;
|
|
9
9
|
sendPayload(payload0: IJsBridgeMessagePayload | string): void;
|
|
10
|
+
_getOriginFromPort(port: chrome.runtime.Port): string;
|
|
10
11
|
setupMessagePortOnConnect(): void;
|
|
11
12
|
requestToAllCS(scope: IInjectedProviderNamesStrings, data: unknown): void;
|
|
12
13
|
requestToAllUi(data: unknown): void;
|
|
@@ -39,6 +39,20 @@ class JsBridgeExtBackground extends JsBridgeBase {
|
|
|
39
39
|
throw error;
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
+
_getOriginFromPort(port) {
|
|
43
|
+
var _a, _b, _c, _d;
|
|
44
|
+
// chrome
|
|
45
|
+
let origin = ((_a = port === null || port === void 0 ? void 0 : port.sender) === null || _a === void 0 ? void 0 : _a.origin) || '';
|
|
46
|
+
// firefox
|
|
47
|
+
if (!origin && ((_b = port === null || port === void 0 ? void 0 : port.sender) === null || _b === void 0 ? void 0 : _b.url)) {
|
|
48
|
+
const uri = new URL((_c = port === null || port === void 0 ? void 0 : port.sender) === null || _c === void 0 ? void 0 : _c.url);
|
|
49
|
+
origin = (uri === null || uri === void 0 ? void 0 : uri.origin) || '';
|
|
50
|
+
}
|
|
51
|
+
if (!origin) {
|
|
52
|
+
console.error((_d = this === null || this === void 0 ? void 0 : this.constructor) === null || _d === void 0 ? void 0 : _d.name, 'ERROR: origin not found from port sender', port);
|
|
53
|
+
}
|
|
54
|
+
return origin;
|
|
55
|
+
}
|
|
42
56
|
setupMessagePortOnConnect() {
|
|
43
57
|
// TODO removeListener
|
|
44
58
|
chrome.runtime.onConnect.addListener((port) => {
|
|
@@ -55,8 +69,7 @@ class JsBridgeExtBackground extends JsBridgeBase {
|
|
|
55
69
|
const portId = this.portIdIndex;
|
|
56
70
|
this.ports[portId] = port;
|
|
57
71
|
const onMessage = (payload, port0) => {
|
|
58
|
-
|
|
59
|
-
const origin = ((_a = port0.sender) === null || _a === void 0 ? void 0 : _a.origin) || '';
|
|
72
|
+
const origin = this._getOriginFromPort(port0);
|
|
60
73
|
payload.remoteId = portId;
|
|
61
74
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
62
75
|
const jsBridge = this;
|
|
@@ -85,9 +98,8 @@ class JsBridgeExtBackground extends JsBridgeBase {
|
|
|
85
98
|
// TODO optimize rename: broadcastRequest
|
|
86
99
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
87
100
|
entries(this.ports).forEach(([portId, port]) => __awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
var _a;
|
|
89
101
|
if (port.name === EXT_PORT_CS_TO_BG) {
|
|
90
|
-
const origin = (
|
|
102
|
+
const origin = this._getOriginFromPort(port);
|
|
91
103
|
if (isFunction(data)) {
|
|
92
104
|
// eslint-disable-next-line no-param-reassign
|
|
93
105
|
data = yield data({ origin });
|
|
@@ -45,6 +45,20 @@ class JsBridgeExtBackground extends cross_inpage_provider_core_1.JsBridgeBase {
|
|
|
45
45
|
throw error;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
+
_getOriginFromPort(port) {
|
|
49
|
+
var _a, _b, _c, _d;
|
|
50
|
+
// chrome
|
|
51
|
+
let origin = ((_a = port === null || port === void 0 ? void 0 : port.sender) === null || _a === void 0 ? void 0 : _a.origin) || '';
|
|
52
|
+
// firefox
|
|
53
|
+
if (!origin && ((_b = port === null || port === void 0 ? void 0 : port.sender) === null || _b === void 0 ? void 0 : _b.url)) {
|
|
54
|
+
const uri = new URL((_c = port === null || port === void 0 ? void 0 : port.sender) === null || _c === void 0 ? void 0 : _c.url);
|
|
55
|
+
origin = (uri === null || uri === void 0 ? void 0 : uri.origin) || '';
|
|
56
|
+
}
|
|
57
|
+
if (!origin) {
|
|
58
|
+
console.error((_d = this === null || this === void 0 ? void 0 : this.constructor) === null || _d === void 0 ? void 0 : _d.name, 'ERROR: origin not found from port sender', port);
|
|
59
|
+
}
|
|
60
|
+
return origin;
|
|
61
|
+
}
|
|
48
62
|
setupMessagePortOnConnect() {
|
|
49
63
|
// TODO removeListener
|
|
50
64
|
chrome.runtime.onConnect.addListener((port) => {
|
|
@@ -61,8 +75,7 @@ class JsBridgeExtBackground extends cross_inpage_provider_core_1.JsBridgeBase {
|
|
|
61
75
|
const portId = this.portIdIndex;
|
|
62
76
|
this.ports[portId] = port;
|
|
63
77
|
const onMessage = (payload, port0) => {
|
|
64
|
-
|
|
65
|
-
const origin = ((_a = port0.sender) === null || _a === void 0 ? void 0 : _a.origin) || '';
|
|
78
|
+
const origin = this._getOriginFromPort(port0);
|
|
66
79
|
payload.remoteId = portId;
|
|
67
80
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
68
81
|
const jsBridge = this;
|
|
@@ -91,9 +104,8 @@ class JsBridgeExtBackground extends cross_inpage_provider_core_1.JsBridgeBase {
|
|
|
91
104
|
// TODO optimize rename: broadcastRequest
|
|
92
105
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
93
106
|
(0, entries_1.default)(this.ports).forEach(([portId, port]) => __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
var _a;
|
|
95
107
|
if (port.name === EXT_PORT_CS_TO_BG) {
|
|
96
|
-
const origin = (
|
|
108
|
+
const origin = this._getOriginFromPort(port);
|
|
97
109
|
if ((0, isFunction_1.default)(data)) {
|
|
98
110
|
// eslint-disable-next-line no-param-reassign
|
|
99
111
|
data = yield data({ origin });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/extension-bridge-hosted",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"cross-inpage-provider"
|
|
6
6
|
],
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"start": "tsc --watch"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@onekeyfe/cross-inpage-provider-core": "^0.0.
|
|
32
|
-
"@onekeyfe/cross-inpage-provider-types": "^0.0.
|
|
31
|
+
"@onekeyfe/cross-inpage-provider-core": "^0.0.4",
|
|
32
|
+
"@onekeyfe/cross-inpage-provider-types": "^0.0.4"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "d47447804157874b2607aea82f92ff3a132c5e67"
|
|
35
35
|
}
|