@onekeyfe/extension-bridge-injected 0.0.9 → 0.0.12
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.
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { IJsBridgeConfig, IJsBridgeMessagePayload } from '@onekeyfe/cross-inpage-provider-types';
|
|
1
|
+
import { IJsBridgeConfig, IJsBridgeMessagePayload, IOptionsWithDebugLogger } from '@onekeyfe/cross-inpage-provider-types';
|
|
2
2
|
import { JsBridgeBase } from '@onekeyfe/cross-inpage-provider-core';
|
|
3
3
|
declare function getOrCreateExtInjectedJsBridge(options?: IJsBridgeConfig): JsBridgeBase;
|
|
4
|
+
export declare type ISetupPostMessageListenerOptions = IOptionsWithDebugLogger & {
|
|
5
|
+
bridge?: JsBridgeBase;
|
|
6
|
+
};
|
|
4
7
|
declare class JsBridgeExtInjected extends JsBridgeBase {
|
|
5
8
|
constructor(config: IJsBridgeConfig);
|
|
6
9
|
sendAsString: boolean;
|
|
@@ -19,7 +19,7 @@ function setupPostMessageListener(options = {}) {
|
|
|
19
19
|
// - receive
|
|
20
20
|
// #### content-script -> injected
|
|
21
21
|
window.addEventListener('message', (event) => {
|
|
22
|
-
var _a;
|
|
22
|
+
var _a, _b;
|
|
23
23
|
// We only accept messages from ourselves
|
|
24
24
|
if (event.source !== window) {
|
|
25
25
|
return;
|
|
@@ -30,7 +30,7 @@ function setupPostMessageListener(options = {}) {
|
|
|
30
30
|
eventData.direction === JS_BRIDGE_MESSAGE_DIRECTION.HOST_TO_INPAGE) {
|
|
31
31
|
debugLogger.extInjected('onWindowPostMessage', eventData);
|
|
32
32
|
const payload = eventData.payload;
|
|
33
|
-
const jsBridge = (_a = window === null || window === void 0 ? void 0 : window.$onekey) === null ||
|
|
33
|
+
const jsBridge = (_a = options.bridge) !== null && _a !== void 0 ? _a : (_b = window === null || window === void 0 ? void 0 : window.$onekey) === null || _b === void 0 ? void 0 : _b.jsBridge;
|
|
34
34
|
if (jsBridge) {
|
|
35
35
|
jsBridge.receive(payload);
|
|
36
36
|
}
|
|
@@ -42,10 +42,13 @@ class JsBridgeExtInjected extends JsBridgeBase {
|
|
|
42
42
|
super(config);
|
|
43
43
|
this.sendAsString = false;
|
|
44
44
|
this.isInjected = true;
|
|
45
|
+
// receive message
|
|
45
46
|
setupPostMessageListener({
|
|
46
47
|
debugLogger: this.debugLogger,
|
|
48
|
+
bridge: this,
|
|
47
49
|
});
|
|
48
50
|
}
|
|
51
|
+
// send message
|
|
49
52
|
sendPayload(payloadObj) {
|
|
50
53
|
window.postMessage({
|
|
51
54
|
channel: JS_BRIDGE_MESSAGE_EXT_CHANNEL,
|
|
@@ -23,7 +23,7 @@ function setupPostMessageListener(options = {}) {
|
|
|
23
23
|
// - receive
|
|
24
24
|
// #### content-script -> injected
|
|
25
25
|
window.addEventListener('message', (event) => {
|
|
26
|
-
var _a;
|
|
26
|
+
var _a, _b;
|
|
27
27
|
// We only accept messages from ourselves
|
|
28
28
|
if (event.source !== window) {
|
|
29
29
|
return;
|
|
@@ -34,7 +34,7 @@ function setupPostMessageListener(options = {}) {
|
|
|
34
34
|
eventData.direction === JS_BRIDGE_MESSAGE_DIRECTION.HOST_TO_INPAGE) {
|
|
35
35
|
debugLogger.extInjected('onWindowPostMessage', eventData);
|
|
36
36
|
const payload = eventData.payload;
|
|
37
|
-
const jsBridge = (_a = window === null || window === void 0 ? void 0 : window.$onekey) === null ||
|
|
37
|
+
const jsBridge = (_a = options.bridge) !== null && _a !== void 0 ? _a : (_b = window === null || window === void 0 ? void 0 : window.$onekey) === null || _b === void 0 ? void 0 : _b.jsBridge;
|
|
38
38
|
if (jsBridge) {
|
|
39
39
|
jsBridge.receive(payload);
|
|
40
40
|
}
|
|
@@ -46,10 +46,13 @@ class JsBridgeExtInjected extends cross_inpage_provider_core_2.JsBridgeBase {
|
|
|
46
46
|
super(config);
|
|
47
47
|
this.sendAsString = false;
|
|
48
48
|
this.isInjected = true;
|
|
49
|
+
// receive message
|
|
49
50
|
setupPostMessageListener({
|
|
50
51
|
debugLogger: this.debugLogger,
|
|
52
|
+
bridge: this,
|
|
51
53
|
});
|
|
52
54
|
}
|
|
55
|
+
// send message
|
|
53
56
|
sendPayload(payloadObj) {
|
|
54
57
|
window.postMessage({
|
|
55
58
|
channel: JS_BRIDGE_MESSAGE_EXT_CHANNEL,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/extension-bridge-injected",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
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.12",
|
|
32
|
+
"@onekeyfe/cross-inpage-provider-types": "^0.0.12"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "8d2544a62c77934ce19b19439476bf35d88bd5b8"
|
|
35
35
|
}
|